How to overwrite a cout.

Hi guys, may i know how do i overwrite a statement in cout. More explanation on code-flow below

Using a switch case and example.

Menu 1
1
2
3
4
5
6
7
8
 cout<<"Welcome to Assn3 program!"<<endl<<
   
      "1)Read in data."<<endl<<
      "2)Specify filtering criteria (current: Point2D)"<<endl<<
      "3)Specify sorting criteria (current : x-cordinate)"<<endl<<   		
      "4)Specify sorting order (current: ASC)."<<endl<<
      "5)View Data"<<endl<<
      "6)Store Data"<<endl;


The user will select option 2 and go to menu 2.

Menu 2

1
2
3
4
5
cout<<"[Specifying flitering critiera (current: Point2D)]"<<endl;
			cout<<"a)	Point2D records"<<endl;
		        cout<<"b)	Point3D records"<<endl;
			cout<<"c)	Line2D records"<<endl;
			cout<<"d)	Line3D records"<<endl;


After coming to menu 2, user can select upon these records.

For example i select b which is Point3D records, how do i overwrite the option 2 in menu 1 to specify the current sorting criteria has been changed to Point3D?


Do you mean you want to clear the screen and write something else on the screen?
No as in i wished to overwrite the statement in menu 1 choice 2 to
Specify filtering criteria (current: Point3D) after the user selects
choice b in menu 2
1
2
3
4
5
6
7
8
 cout<<"Welcome to Assn3 program!"<<endl<<
   
      "1)Read in data."<<endl<<
      "2)Specify filtering criteria (current: Point3D)"<<endl<<
      "3)Specify sorting criteria (current : x-cordinate)"<<endl<<   		
      "4)Specify sorting order (current: ASC)."<<endl<<
      "5)View Data"<<endl<<
      "6)Store Data"<<endl;


Like that?

yes. According to which choice he selects in menu 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if (userchoseoneoption)
{
  cout<<"Welcome to Assn3 program!"<<endl<<
   
      "1)Read in data."<<endl<<
      "2)Specify filtering criteria (current: Point2D)"<<endl<<
      "3)Specify sorting criteria (current : x-cordinate)"<<endl<<   		
      "4)Specify sorting order (current: ASC)."<<endl<<
      "5)View Data"<<endl<<
      "6)Store Data"<<endl;
}

if (userchoseotheroption)
{
  cout<<"Welcome to Assn3 program!"<<endl<<
   
      "1)Read in data."<<endl<<
      "2)Specify filtering criteria (current: Point3D)"<<endl<<
      "3)Specify sorting criteria (current : x-cordinate)"<<endl<<   		
      "4)Specify sorting order (current: ASC)."<<endl<<
      "5)View Data"<<endl<<
      "6)Store Data"<<endl;
}


More elegantly
1
2
3
4
5
6
7
8
9
10
11
12
if (userchoseoneoption)
{ optionString = "2)Specify filtering criteria (current: Point3D)";}
else
{ optionString = "2)Specify filtering criteria (current: Point2D)";}
  cout<<"Welcome to Assn3 program!"<<endl<<
   
      "1)Read in data."<<endl<<
      optionString  <<endl<<
      "3)Specify sorting criteria (current : x-cordinate)"<<endl<<   		
      "4)Specify sorting order (current: ASC)."<<endl<<
      "5)View Data"<<endl<<
      "6)Store Data"<<endl;

Thanks alot! =)
1
2
3
4
5
6
string filter_criteria[] = {"Point2D", "Point3D" /*...*/};

  cout<<"Welcome to Assn3 program!"<<endl<<
   
      "1)Read in data."<<endl<<
      "2)Specify filtering criteria (current: " << filter_criteria[ filter_option ]<<endl<<
Topic archived. No new replies allowed.