C++ file streams?
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 ...
The information post by website user , we not guarantee correctness.
Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes
