Hi guys i'm trying to write a programme as follow:
Write a program that:
1) Prompt the user to enter a file name to save the inputs.
2) Prompt the user to enter information/statements.
3) Save the information/statements entered by user to the file name given early.
4) Close the file.
5) Reopen the input file
6) Read all info from the file.
7) Reverse all characters from the reading.
8) Prompt the user to enter a file name to save the outputs.
9) Write the reversed results to the file.
Do not use reverse function provided in the algorithm header file.
Suppose the user specifies input.txt and output.txt when prompted for the file names
Below is my current progress, I am able to transfer the user input to the text file but what if the user wants to input multiple lines, my programme can only transfer it in one line, also how can i stop the user input when a specific character is entered?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string input_file, output_file;
char statement[100];
do {
cout << "Please enter a file name for input file : " << flush;
cin >> input_file;
if (input_file != "userinput") {
cout << "File name unavailable!" << endl;
}
} while (input_file != "userinput");
ofstream userinput("input.txt");
cout <<"Please enter your information/statement (Enter a dot to stop) :"<< flush;
do{
cin.getline(statement,100);
userinput << statement << " " << flush;
}while(statement != ".");
}
|