我需要使用字符串流从文件中读取表达式,并将表达式转换为另一种形式。但我无法弄清楚如何使用Istringstream从文件中读取行。任何人都可以帮助我#includes和语法吗?感谢
答案 0 :(得分:1)
#include <fstream>
std::ifstream file("filename.txt");
StuffType stuff;
while(file >> stuff)
{
// If you are here you have successfully read stuff.
}
答案 1 :(得分:1)
作为上述Dave答案的补充:要从文件中读取一行,您可以使用以下代码:
char buf[256];
file.getline(buf,256);
字符串buf则包含文件中的文本行。