C++ file streams?

 Dont Buy Textbooks. Rent 'EM Save 60-80%



I'm kind of stumped on this one. I want to read in a .txt file with C++'s ifstream object and save it to a string object.

The problem is: I'm having trouble saving the entire contents of the file to a single string, so I can manipulate it.

How can I do that ? >.<

C++ file streams?c++ compiler



I would use an array of strings. First read the whole file and enumerate the number of lines involved lets call this n, use a while loop for doing this:

while(file.readline())

{

n++;

};

Create string array:

String[] arr = new String[n];

fill in the lines for each line in the file:

int m = 0;

while(file.readline())

{

arr[m] = file.readline().toString();

m++;

}

Then you can manipulate the array of strings, and when you want you can append the strings using a simple for loop.

Also consider the StringBuilder Class it might be a more precise solution.

C++ file streams?c++ cli



dont use any feedbacks like new line tabs etc



More Related Questions and Answers ...
  • Using fstream (Visual C++)?
  • How do I convert a c-style string of chars in..
  • Help With My C++ Program PLEASE?
  • C++ Help Again =( !?
  • HELP with a C++ program reading students grad..
  • C++ Help... I cant figure this one out.. Plea..
  • C++ HELP, I can get the program running, but ..
  • C++ program question?
  • C++ code to replace words in a document, keep..
  • Need help with c++ programming please?
  • C++ programming?
  • Why am i getting this c++ error?
  • C++ help help help, almost can get it but not..
  • For file io in c++ how do i count all the wor..
  • C++ Problem?
  • Help with outfile in Bloodsheed C++?
  • Need help with io in C++, have read much prog..
  • C++: How do you edit a char string from a dif..
  • C++ Error message?

  • The information post by website user , we not guarantee correctness.

    

    Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes