我注意到一個奇怪的行爲,只是下面這個非常簡單的程序。使用「>>」運算符使用std :: istringstream的奇怪行爲
#include <iostream>
#include <sstream>
#include <string>
int main(void)
{
std::string data = "o BoxModel\nv 1.0f, 1.0f, 1.0f\nv 2.0f, 2.0f, 2.0f\n";
std::istringstream iss(data);
std::string line;
std::string type;
while (std::getline(iss, line, '\n'))
{
iss >> type;
std::cout << type << std::endl;
}
getchar();
return (0);
}
輸出如下:
v
v
v
但我想下面的一個:
o
v
v
我試過這個解決方案:
#include <iostream>
#include <sstream>
#include <string>
int main(void)
{
std::string data = "o BoxModel\nv 1.0f, 1.0f, 1.0f\nv 2.0f, 2.0f, 2.0f\n";
std::istringstream iss(data);
std::string line;
std::string type;
iss >> type;
std::cout << type << std::endl;
while (std::getline(iss, line, '\n'))
{
iss >> type;
std::cout << type << std::endl;
}
getchar();
return (0);
}
但輸出如下:
o
v
v
v
有人能幫助我嗎?提前感謝您的幫助。
好像你試圖做*你* * *時(:。 – Rubens