Reading and writing from a file

Write your question here.

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
30
31
32
33
34
  #include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{

	ifstream inFile;
	inFile.open("message.txt");
	

	//Check to see if open
	if (inFile.fail())
	{
		cout << "File cannot be opened" << endl;
		exit(1);
	}

	char c;
	while (inFile.get(c))          // loop getting single characters
		cout << c;

	inFile.close();                // close file







	return 0;
}



So I am not looking for answers, just a little direction with reading and writing to a file. So I have successfully opened my file, and it reads it just fine. I am trying to rewrite the data in another file figuring out if the data is upper case or lower case, and rewriting it all in upper case. Just a little direction would help, thank you.
Basically you need to create a output file (ofstream) and in the loop where you read from the input you need to check if it is lower case then convert to upper case and write to the output file.

To convert to upper case you can use the toupper function, to check if is lower case you have to write your own function.
Topic archived. No new replies allowed.