read word by word from file in C++

后端 未结 5 880
清歌不尽
清歌不尽 2020-12-01 12:53

this function should read a file word by word and it does work till the last word, where the run stops

void readFile(  )
{
    ifstream file;
    file.open          


        
5条回答
  •  半阙折子戏
    2020-12-01 13:22

    I have edited the function for you,

    void readFile()
    {
        ifstream file;
        file.open ("program.txt");
        if (!file.is_open()) return;
    
        string word;
        while (file >> word)
        {
            cout<< word << '\n';
        }
    }
    

提交回复
热议问题