c++中的setiosflags(ios::skipws)怎么用?
我敲的char*pt="China";cout<<setiosflags(ios::skipws)<<pt<<endl;没有达到忽略空格效果。我用的是VC6.0难道是编译...
我敲的char* pt = " Ch ina"; cout<<setiosflags(ios::skipws)<<pt<<endl;没有达到忽略空格效果。我用的是VC6.0难道是编译器的问题?(前面已加include<iomanip>)
展开
展开全部
关于skipws,C++规范中描述如下:
Skip whitespaces
Sets the skipws format flag for the str stream.
When the skipws format flag is set, as many whitespace characters as necessary are read and discarded from the stream until a non-whitespace character is found before. This applies to every formatted input operation performed with operator>> on the stream.
Tab spaces, carriage returns and blank spaces are all considered whitespaces (see isspace).
This flag can be unset with the noskipws manipulator, forcing extraction operations to consider leading whitepaces as part of the content to be extracted.
For standard streams, the skipws flag is set on initialization.
其功能为忽略空白字符。用于输入流中,如cin。在标准输入流中,skipws已经是默认开启状态。
skipws会忽略空白字符,包括空格,制表符(\t),换行符(\n)等不可见字符。
如果系统当前skipws开关已经关闭,那么可以在输入流中,插入skipws来打开。
stream<<setiosflags(ios::skipws);
Skip whitespaces
Sets the skipws format flag for the str stream.
When the skipws format flag is set, as many whitespace characters as necessary are read and discarded from the stream until a non-whitespace character is found before. This applies to every formatted input operation performed with operator>> on the stream.
Tab spaces, carriage returns and blank spaces are all considered whitespaces (see isspace).
This flag can be unset with the noskipws manipulator, forcing extraction operations to consider leading whitepaces as part of the content to be extracted.
For standard streams, the skipws flag is set on initialization.
其功能为忽略空白字符。用于输入流中,如cin。在标准输入流中,skipws已经是默认开启状态。
skipws会忽略空白字符,包括空格,制表符(\t),换行符(\n)等不可见字符。
如果系统当前skipws开关已经关闭,那么可以在输入流中,插入skipws来打开。
stream<<setiosflags(ios::skipws);
展开全部
skipws是作用于流式输入的,而非输出。
cin默认是已经把skipws开启了。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char s1,s2,s3;
cin>>resetiosflags(ios::skipws);
cin>>s1>>s2>>s3;
cout<<s1<<s2<<s3<<endl;
return 0;
}
注意把cin>>resetiosflags那句注释和不注释,看输入的差别,你就明白了。
cin默认是已经把skipws开启了。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char s1,s2,s3;
cin>>resetiosflags(ios::skipws);
cin>>s1>>s2>>s3;
cout<<s1<<s2<<s3<<endl;
return 0;
}
注意把cin>>resetiosflags那句注释和不注释,看输入的差别,你就明白了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询