rewriting c++ code with cin,cout

Hey Guys,

I need help rewriting this function with newer c++ code and using cin/cout instead scanf/printf

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
//the view function
void view()
{
char choice3;
//opening the Records file
		Records = fopen("Records.txt","a+");
		do
		{
			fgets(info,SIZE,Records);
			printf("%s\n",info);

		}while(!feof(Records));
			fclose(Records);
			system("pause");
			printf("Search for records??(Y/N)\n");
			scanf("%c",&choice3);
			fflush(stdin);
			if (toupper(choice3)=='Y')
			{
			search();
		}
		else if(toupper(choice3)=='N')
		{
			fclose(Records);
			system("pause");
			system("cls");
			main_function();
		}

		else
		{
			fclose(Records);
			system("cls");
		}
}
Well, just replace them. If you are unsure now exactly it probably is because you need to read about it .

cin: http://www.cplusplus.com/reference/iostream/cin/
cout: http://www.cplusplus.com/reference/iostream/cout/

Also check out pretty much ANY console code sample you can get to see how these are used. For example, ideone.com has a lot of code samples (both good and bad). Check them out after reading the documentation and you'll easily complete this task.
Ok, Thanks I did. Is it correct?
Does this code looks like modern c++ code? or still looks like c code...

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
//the view function
void view()
{
char choice3;
//opening the Records file
		Records = fopen("Records.txt","a+");
		do
		{
			fgets(info,SIZE,Records);
                        cout << info;

		}while(!feof(Records));
			fclose(Records);
			system("pause");
			cout << "Search for records??(Y/N)" << endl;
                        cin >> choice3;
			fflush(stdin);
			if (toupper(choice3)=='Y')
			{
			search();
		}
		else if(toupper(choice3)=='N')
		{
			fclose(Records);
			system("pause");
			system("cls");
			main_function();
		}

		else
		{
			fclose(Records);
			system("cls");
		}
}
C++ provide ifstream for reading input from files; fopen and fclose calls are C style.

system("cls"); and system("pause"); are bad form in C and C++.
Thanks can plz you help me correct it
Topic archived. No new replies allowed.