Created
December 7, 2014 08:55
-
-
Save Mooophy/1a307592d2ed15c83a00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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