ofstream isitn working..

My function does not overwrite or add a newline to my text file :(

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
50
51
52
53
54
55
56
57
58
59
void newaccount()
{
	fstream fp;
	int nid,id, npw, pw, renid, repw, newaccount=1;
	int nscore=0, nunlocked=1, score, unlocked, rank;
	fp.open("membership.txt", fstream::in);
	if(!fp) cout<<"Unable to open file under input mode!";
	else
	{
		while(!fp.eof() )
		{ 
			fp>>id>>pw>>score>>unlocked>>rank;
			if(fp.fail()) { break; system("pause");}
		}
		fp.close();

		fp.open("membership.txt", fstream::app) ;
		if(!fp) cout<<"Unable to open file under app mode!";
		else
		{
			while(true)
			{ 
				cout<<"Please enter your desired Username and Password!"<<endl;
				cin>>nid>>npw;
				cout<<"Please re-enter your desired Username and Password!"<<endl;
				cin>>renid>>repw;
				if (nid == renid && npw == repw)
				{	
					cout<<"Congratulations! Your account has been created successfully!"<<endl;
					break;
				}
				else if (nid != renid || npw!= repw)
				{
					while(nid != renid || npw!= repw)
					{
						cout<<"Username and Password do not match each other!"<<endl;
						cout<<"Please enter your desired Username and Password!"<<endl;
						cin>>nid>>npw;
						cout<<"Please re-enter your desired Username and Password!"<<endl;
						cin>>renid>>repw;
					}
					cout<<"Congratulations! Your account has been created successfully!"<<endl;
					break;
				}		
				else break;
				cout<<endl;
				cout<<"Adding a new record:\n";
				cout<<nid<<" "<<npw<<" "<<endl;
				fp<<nid<<" "<<npw<<" "<<0<<"  "<<0<<"  "<<9999<<endl;
				if(fp.fail()) cout<<"Error encountered while adding data!\n";
				else
				cout<<"Data added!\n";

			}
		}
		fp.close();
	}

}	
Last edited on
That was my post too :( i still couldnt get it to work
p.s. i dont know what vs ide is either..
Last edited on
Topic archived. No new replies allowed.