파일에서 텍스트를 읽어 행이 바뀌는 단위로 vector string을 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | // Load file and read text line by line, make them as vector string // [INPUT] // >> const std::string _fn file name // [OUTPUT] // >> std::vector<std::string>& vs_ readed file bool to_vs ( const std::string _fn, std::vector<std::string>& vs_) { vs_.clear(); std::ifstream fn(_fn); if ( !fn.is_open() ) return false; bool bEOF = false; std::string tmp; while( std::getline(fn, tmp) ) { vs_.push_back(tmp); bEOF = fn.eof(); } fn.close(); // end without eof ( end of file ) : regard "getline" discard '\n' if (!bEOF) vs_.push_back("\n"); return true; } | cs |
'C++' 카테고리의 다른 글
[C++] 현재 시간 얻기 (0) | 2016.10.24 |
---|---|
[C++] string TO vector string (0) | 2016.10.13 |
[C++] 폴더 내 파일목록 읽기 (0) | 2016.04.13 |