string line;
search.open("1.board");
while(getline("1.board",line))
{
cout<<line<<"\n";
}
例如,这里每次循环超过getline都开始指向下一行。怎么样?
std::getline
的简单示例:#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string line;
int lineNumber = 0;
std::ifstream inputStream("1.board");
while (std::getline(inputStream, line))
std::cout << "Line " << ++lineNumber << ": " << line << std::endl;
}