using fstream to read every character including spaces and newline

前端 未结 13 1575
一个人的身影
一个人的身影 2020-12-07 22:47

I wanted to use fstream to read a txt file.

I am using inFile >> characterToConvert, but the problem is that this omits any spaces an

13条回答
  •  天涯浪人
    2020-12-07 23:36

    std::ifstream ifs( "filename.txt" );
    
    std::string str( ( std::istreambuf_iterator( ifs ) ), 
                     std::istreambuf_iterator()
                   );
    

提交回复
热议问题