I/O filestream and objects

My problems are that I am getting some of my output repeated twice and that when i hit anything other than "yes" to repeat the loop I get some of the output that is only supposed to be in the loop. Is my do while loop in the right place? or am i using my i/o streams in the wrong place?


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
38
39
40
41
42
43
44
45
46
47
48
49
  #include<iomanip>
#include<iostream>
#include<string>
#include<cmath>
#include<fstream>
#include<cstdlib>
 
using namespace std;

int main()
{
	string info;
	ofstream file1;
	ifstream file2;
	string ans; 

	file1.open("original.txt.");


	cout<<"Please enter your name and street address"<<endl<<endl;
	
	getline(cin, info);
	file1<<info;
	system("cls");
	
	
	cout<<"Would you like to update your street address?"<<endl;
	cin>>ans;
	do{
	

		file2.open("original.txt.");
		cout<<info<<endl<<endl;
		
		file1.open("changed_info.txt");
		cout<<"Please input your name and updated address"<<endl;
		getline(cin,info);

		
	}
	while (ans == "yes");

	
	cout<<"Thank you for using this program"<<endl;

	system("pause");

	return 0;
}
Put a cin.sync() before your getline @ line 37.

Also what if I enter no for ans you still enter the loop because it is a do while switch to a while. Once you are in your loop how does ans get updated to exit the loop?
what is "cin.sync()" ? we haven't learned that yet. and ok, that makes sense. Could I put an exit(1) (i think thats the code) somewhere to exit the program?
Topic archived. No new replies allowed.