How to copy a .txt file to a char array in c++

后端 未结 5 887
忘了有多久
忘了有多久 2020-11-27 17:26

Im trying to copy a whole .txt file into a char array. My code works but it leaves out the white spaces. So for example if my .txt file reads \"I Like Pie\" and i copy it to

5条回答
  •  误落风尘
    2020-11-27 18:10

    A simple solution if you're bound to using char arrays, and minimal modification to your code. The snippet below will include all spaces and line breaks until the end of the file.

          while (!myfile.eof())
          {
                myfile.get(myArray[i]);
                i++;
                num_characters ++;
          }  
    

提交回复
热议问题