保存在我的文件數據的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'被禁止,而是與格式化輸入不跳過前導空白。 –