我正在制作一个程序,您可以在其中登录和注册。所有的数据都存储在一个.txt文件中。我现在遇到的问题是,当我试图从文件中获取所有数据时,我只能得到文件的第一行/字符串。我想让.txt中的所有内容。下面是一些代码:C++从.txt中读取所有内容
是什么在.TXT:
hello:world
foo:bar
usr:pass
代码(作为测试):
ifstream check;
check.open("UsrInfo.txt");
string dataStr;
getline(check, dataStr);
cout << dataStr;
cout << endl;
输出:
hello:world
我想要的输出成为:
hello:world
foo:bar
usr:pass
我能做些什么来解决这个问题?谢谢!
的可能的复制[逐行读取文件中的行(http://stackoverflow.com/questions/7868936/read-file-line-by-line) – soon
'我只得到了第一line'有你考虑重复其他行相同的操作? [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)可能有帮助。 – Drop