那个和 之间有什么区别(listfile.getline(缓冲区,100)) ?为什么需要双倍'''''? - " Codito ergo sum" Roel Schroeven What''s the difference between that and while (listfile.getline(buffer, 100)) ? Why the need for the double ''!''? --"Codito ergo sum"Roel Schroeven John写道:大家好, 我试图从文件中读入缓冲区。通常情况下我会做这个非常低级的,但是我得出结论我必须停止做所有事情。所以,我想我会尝试< ; fstream的取代。下面的代码在while()语句中导致无限循环。调试,我看到缓冲区在第一个位置只有一个0,没有别的。 ifstream listfile; listfile.open(" data \\modellist.txt",ios :: in); if(listfile.bad())返回0; char buffer [100]; while(!listfile.getline(buffer,100).eof()) { //用缓冲区做的东西 } 试试 std :: ifstream listfile(filename,std :: ios_base :: in); if(stream) { std :: string s; while(std :: getline(listfile,s)) { //做东西 } } 您是否从正确的目录中运行? 任何人都知道为什么?文件没问题,并且在fread之类的情况下工作正常。 bad()与good()不相反。 提前致谢! Hello all, I am trying to read in lines into a buffer from a file. Normally I would do this very low-level, but I have come to the conclusion I must stop doing everything the hard way. So, I thought I would try <fstream>. The code below causes an infinite loop in the while() statement. Debugging, I see that the buffer just has a 0 in the first position, and nothing else. ifstream listfile; listfile.open("data\\modellist.txt", ios::in); if(listfile.bad()) return 0; char buffer[100]; while(!listfile.getline(buffer, 100).eof()) { //Do stuff with buffer }Try std::ifstream listfile (filename, std::ios_base::in); if (stream){std::string s;while (std::getline (listfile, s)){// do stuff}} Are you running from the right directory? Anyone know why? The file is ok, and works fine with fread and the like. bad () is not the opposite of good (). Thanks in advance! 这篇关于ifstream getline()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 07:43