Problem reading in Data Files

Hello, I am trying to read in a Data file and I am having some issues. My problem is that I need to read in a file with an unkown amount of phone numbers.
For example my data file is this..
111111 A 2044444444
222222 B 4055532456 1256950334
333333 C 5064064054
444444 D 5063050055

When I use my current code, the output ignores the account number, and uses the plan type as the account number, then the first digit of the phone number as the plan type. I have never done anything like this before, and I have no idea what I'm doing wrong. This is my code so far...

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
  #include<stdlib.h>
#include<iomanip>
#include<iostream>
#include<conio.h>
#include<fstream>
 using namespace std;
  
 int main()
 {
	float minutes, texts, data;
	  char idnum[6], planname, phonenum[12];
	  char ch;

	cout.unsetf(ios::right);
	cout.setf(ios::left);
	system("cls");	     
	ifstream inFile("test.txt",ios::in);
	inFile >> idnum >> planname >> phonenum;
	while(!inFile.eof())
		{
		cout << "Plan ID " << idnum;
		cout <<"\n";
   do {
   	cout << "Plan Type " << planname;
		cout << "\n";		
      	cout << "Phone Number " << phonenum;
		cout << "\n";   
		 ch = inFile.peek();     // check if newline follows
           inFile >> planname >> phonenum;          // read next number        
      } while (ch != '\n');   
		inFile >> idnum >> planname >> phonenum;
		}
}



Any help would be appreciated, and I know my code is messy, but this is only the start of my assignment.
a) i suggest instead of using standard c libraries like this: #include <x.h> use it like this: #include <cx>
b) dont use system
c) i wouldnt use conio. its deprecated
d) since you seem to like writing c code, you could either use a raw pointer or a basic linked list, or if you want to go the c++ route, i would use a container in the stl, such as std::list, std::vector, std::stack, etc
Topic archived. No new replies allowed.