using fstream to read every character including spaces and newline

前端 未结 13 1563
一个人的身影
一个人的身影 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:31

    Another better way is to use istreambuf_iterator, and the sample code is as below:

    ifstream inputFile("test.data");
    
    string fileData(istreambuf_iterator(inputFile), istreambuf_iterator());
    

提交回复
热议问题