Read data from fstream

前端 未结 1 958
孤街浪徒
孤街浪徒 2021-01-28 09:00

I\'m trying to read data from a fstream but this code doesn\'t work. It puts 0 to the console. Can you help me?

// g++ -Wall main.cpp -o main.exe

#include 

        
1条回答
  •  清歌不尽
    2021-01-28 09:38

    Just try this code this code will help you

    #include 
    #include 
    #include 
    //#include 
    using namespace std;
    int main()
    {
    fstream file("main.txt");
    
    file << "45634w6\n";
    file << "dtusrjt\n";
    file.close();
    file.open("main.txt");
        string line;
    while (!file.fail())
    {
        getline(file, line);
        cout <> a;
    }
    

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