Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 c++ 实现一个程序,但我遇到了从输入文件中获取下一行的问题。我用了:
const MAX 300; char oneline[MAX]; ifstream in; in.open("input.txt); in.getline(oneline,MAX);
该函数getline总是让我获得文件中的第一行。问题是,我怎样才能得到文件中的下一行?
getline
std::string line; while(in.good()) { getline(in, line); //do something with line }
Since you're using C++ you should use std::string to read your lines.
while (getline(in,line,'\n')){ //do something with line }