I/O File streams in C++ HW...

I need to write a program that:

Using a text editor (i.e. Notepad), create a text file called Text1.txt and place it into the root directory C:/.
Fill Text1.txt with a sentence and save the file using the text editor menu.
Then, write a C++ program that performs the following:

1. Reads the sentence from the file Text1.txt and display it on the screen.

2. Counts the number of characters of the sentence (including the whitespaces, but excluding the terminating NULL) and displays such information.

3. Replaces the original sentence in Text1.Txt with the reversed sentence (i.e “the cat is on the table” with “elbat eht no si tac eht”) and saves the updated file Text1.txt.

NOTE: Every file must be explicitly opened and then closed immediately after the read/write operations.

I'm inbetween using an array or a string, i havent a clue which would be simpler to use...

And I'm a good visual learner so if u could leave snippits of programming with comments to help me understand, that would be greatly appreciated. Thanks!
I would go with the string in a for loop.
If it's just one line you don't even need to loop. std::string methods and the STL reverse algorithm make this assignment super-simple!

Here are some references:
http://www.cplusplus.com/reference/iostream/fstream/
http://www.cplusplus.com/reference/string/string/
http://www.cplusplus.com/reference/string/getline/
http://www.cplusplus.com/reference/algorithm/reverse/
Ok

so this is what i have

im trying to get this text file named "BLAH" into a string, then after that im pretty much golden

oh and then after i manipulate it as i see fit i need to get it saved into the same file name.....help?

i have this so far:

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;

int main ()
{

ifstream FILE;
FILE.open ("BLAH.txt", ios::out);

char str1[80];

cout << FILE <<endl;


return 0;
}
Topic archived. No new replies allowed.