Skip to content

Instantly share code, notes, and snippets.

@Mooophy
Created December 7, 2014 08:55
Show Gist options
  • Select an option

  • Save Mooophy/1a307592d2ed15c83a00 to your computer and use it in GitHub Desktop.

Select an option

Save Mooophy/1a307592d2ed15c83a00 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stdexcept>
#include <iterator>
class FileReader
{
public:
FileReader(std::string fn): ifs_{fn}
{
if(!ifs_.good())
throw std::runtime_error{"can not open file"};
}
bool is_end() const
{
return ifs_.eof();
}
std::string read()
{
std::string line;
std::getline(ifs_, line);
return line;
}
private:
std::ifstream ifs_;
};
int main()
{
for(FileReader file{"simulation1.txt"}; ! file.is_end(); )
{
std::string line = file.read();
if(line[0] == '#') continue;
std::stringstream ss{line};
for(std::string token; std::getline(ss, token, ' '); )
{
if(token[0] == '\r') continue;
std::cout << token << std::endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment