Reading from textfile problem.

Why is it that when i write/read from my text file, my second line is missing the first digit?

Example im trying to saving to the file like this:

firstName lastName
(425)123-4567

instead im getting this:

firstName lastName
425)123-4567

My first parenthesis is getting left off. Can anyone help me solve this problem?

Here are my write/read functions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void writeFile()
{
	ofstream fout(FILENAME.c_str());
	fout << u1.name << endl;
	fout << u1.phoneNumber << endl;
	fout << u1.servicePin << endl;
	fout.close();
	
}

void readFile()
{
	ifstream fin (FILENAME.c_str());
	if (fin)
   {
		getline(fin, u1.name);
		getline(fin, u1.phoneNumber);
		getline(fin, u1.servicePin);
		cout << "Name: " << u1.name << endl;
		cout << "Phone: " << u1.phoneNumber << endl;
		fin.close();
   }

}


I save the servicePin, but I don't want that to show so i don't display it. It works fine.
Last edited on
Nevermind this topic. The problem wasn't with saving or reading.
Topic archived. No new replies allowed.