首页 > 代码库 > scanf ---------未完待续

scanf ---------未完待续

1.不可读入空格

#include<iostream>#include<stdio.h>using namespace std;int main(){	char c[50];	scanf("%s",c);	printf("%s",c);	return 0;}

2.可以读入空格

用字符 ^ 可以说明补集。把 ^ 字符放为扫描集的第一字符时,构成其它字符组成的命令的补集合,指示 scanf() 只接受未说明的其它字符。

 

#include<iostream>#include<stdio.h>using namespace std;int main(){	char c[50];	scanf("%[^\n]",c);//	printf("%s",c);	return 0;}