📅  最后修改于: 2022-03-11 14:44:46.862000             🧑  作者: Mango
#include
#include
#include
#include
int main()
{
std::fstream file("myfile.txt");
std::vector vec;
if(file.is_open())
{
std::string line;
bool Skip = true;
while(std::getline(file, line))
{
std::stringstream sstr(line);
std::string word;
while (std::getline(sstr, word, ' '))
{
if(!word.empty())
vec.emplace_back(word);
else if(word.empty() && Skip)
{
vec.emplace_back("NaN");
Skip = false;
}
}
Skip = true;
}
file.close();
}
for(size_t i = 0; i < vec.size(); ++i)
{
std::cout << vec[i] << " ";
if((i+1)%3 ==0) std::cout << std::endl;
}
return 0;
}