using fstream to read every character including spaces and newline

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

    The following c++ code will read an entire file...

    
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    int main () 
    {
      string line;
      ifstream myfile ("foo.txt");
    
      if (myfile.is_open()){
    
        while (!myfile.eof()){
          getline (myfile,line);
          cout << line << endl;
        }
        myfile.close();
      }
      return 0;
    }
    
    

    post your code and I can give you more specific help to your problem...

    0 讨论(0)
提交回复
热议问题