Help control the flow of reading and writing problems

I have a solution:
A text file of all lowercase characters read, and then convert it to uppercase characters, and finally write a text file.
I do not know how to write, please help me to write this project. Thanks!
Here is read out and conversion, to help me write a function to write
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
//#include<vector>
#include<fstream>
#include<string>
using namespace std;

void main()
{
	char ch;
	ifstream in("d:\\c++\\data.txt");
	while(!in.eof())
	{
	in.get(ch);
	if(ch>'a' && ch<'z')
	{

		ch = ch-32;
	}
	cout<< ch;
	}
	
	in.close();

}
Lets fix the formatting shall we. ;) And do NOT make "main()" return void. ;O "But Turbine It's so much simpler", that's how the operating system knows if it was successfully running.

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
35
36
37
#include<iostream>
//#include<vector>
#include<fstream>
#include<cstring>
using namespace std;

int main()
{
   const char LOCATION[] = "d:\\c++\\data.txt";
   char ch;

   ifstream in(LOCATION);
   while(!in.eof())
   {
      in.get(ch);
      if(ch >= 'a' && ch <= 'z')  //Check if lower case letter
      {
         ch = ch - 32;
      }

      cout << ch << endl;
   }

   in.close();

   char write[] = "lets write this eh?\nsound good\nisanybodythere";
   ofstream out(LOCATION, ios::trunc);
   for(int i = 0; i < strlen(write); i++)
   {
      ch = toupper(write[i]);
      out.write(&ch, 1);
   }

   out.close();

   return 1;
}

Bottom half covers rest really simply, the reading however has a bug. If no file exists. ;)
Last edited on
Topic archived. No new replies allowed.