C++ 从文件中读取以空格分隔的数字

C++ 从文件中读取以空格分隔的数字,c++,C++,代码 1 3 2 4 5 file.ignore(std::numeric_limits::max(),'\n'); 将跳过所有内容到下一个换行符。在这种情况下,你可能不希望这样 代码 1 3 2 4 5 file.ignore(std::numeric_limits::max(),'\n'); 将跳过所有内容到下一个换行符。在这种情况下,你可能不希望这样 这是一种更惯用的将整数从文件读入向量的方法: file.ignore(std::numeric_limits<std::str

代码

1 3 2 4 5
file.ignore(std::numeric_limits::max(),'\n');
将跳过所有内容到下一个换行符。在这种情况下,你可能不希望这样

代码

1 3 2 4 5
file.ignore(std::numeric_limits::max(),'\n');

将跳过所有内容到下一个换行符。在这种情况下,你可能不希望这样

这是一种更惯用的将整数从文件读入向量的方法:

file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
#包括
#包括
#包括
std::vector loadNumbersFromFile(const std::string&name)
{
std::ifstream是(name.c_str());
std::istream_迭代器开始(is),结束;
返回标准::向量(开始、结束);
}

这是一种将整数从文件读入向量的更惯用方法:

file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
#包括
#包括
#包括
std::vector loadNumbersFromFile(const std::string&name)
{
std::ifstream是(name.c_str());
std::istream_迭代器开始(is),结束;
返回标准::向量(开始、结束);
}