read word by word from file in C++

后端 未结 5 863
清歌不尽
清歌不尽 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:18

    what you are doing here is reading one character at a time from the input stream and assume that all the characters between " " represent a word. BUT it's unlikely to be a " " after the last word, so that's probably why it does not work:

    "word1 word2 word2EOF"
    

提交回复
热议问题