保存在我的文件数据的std :: WS的角色(空格)是(空格都在开始时加入,并在最终的目的本次测试):读取数据时
加载使用下面的代码的数据有或没有“std :: ws”不会导致任何区别。所以我对“std :: ws”的作用感到困惑,因为我已经看到了使用它的代码。有人可以解释一下吗?谢谢!
void main()
{
ifstream inf;
inf.open ("test.txt");
double x=0, y=0, z=0;
string line;
getline(inf, line);
istringstream iss(line);
//Using "std::ws" here does NOT cause any difference
if (!(iss >> std::ws >> x >> y >> z >> std::ws))
{
cout << "Format error in the line" << endl;
}
else
{
cout << x << y << z << endl;
}
iss.str(std::string());
iss.clear();
cin.get();
}
空白在默认情况下,提取开始除去。如果你有'std :: ios_base :: noskipws'或正在使用无格式输入,那么'std :: ws'可能会有用。 – 0x499602D2
@ 0x499602D2该标志被称为'skipws'; 'noskipws'是一个操纵器功能。 – Potatoswatter
@ 0x499602D2:主要用途是没有那么多的时候'的std ::的ios_base :: skipws'被禁止,而是与格式化输入不跳过前导空白。 –