homework help text file to structure

Ok, so I know how structure look but don't know how to use it on my code I need help setting up the structure and reading in the text and printing the results but with name and letter swapped positions.

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
60
  int main()

{
	//Cannot figure out how to do structures and Properly format the output to the file
	struct mine
	{
		int num1;
		char data[10];
		string what;
	};

	//declare a string to hold the text 
	string name,letter,integer,integer2;
	int x,y,users;

	//creates the data file
	ofstream outfile("Test 3.txt");

	cout << "Enter the amount of users to add: ";
	cin >> users;
	cin.ignore();
	// loop for choosing amount of users to add
	for(x=0;x<users;x++)
	{
		
		cout<<"Enter fullname last name first: ";  
		getline(cin, name);

		cout<<"Enter Capital N or S: "; 
		getline(cin, letter);
		

		cout<<"Enter first integer: "; 
		getline(cin, integer);
	

		cout<<"Enter second integer: "; 
		getline(cin, integer2);
		cout <<endl;

		//prints to the file
		outfile<<name<<right<<setw(15)<<letter
			<<right<<setw(20)<<integer
			<<right<<setw(25)<<integer2
			<<right<<setw(30)<<"\n";
	}

	//close the output file 
		outfile.close();
		
		
		ifstream myfile ("test3.txt");
		//Dont Know how to read into and array of structure
		
		
		

	system("pause");
	return 0;
}
Like so:
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
60
61
62
63
64
65
66
67
  int main()

{
	//Cannot figure out how to do structures and Properly format the output to the file
	struct mine
	{
		int num1;
		char data[10];
		string what;
	};

mine all_users[100]; // Note: max 100 ursers / index for 0 to 99 not 100

	//declare a string to hold the text 
	string name,letter,integer,integer2;
	int x,y,users;

	//creates the data file
	ofstream outfile("Test 3.txt");

	cout << "Enter the amount of users to add: ";
	cin >> users;
	cin.ignore();
	// loop for choosing amount of users to add
	for(x=0;x<users;x++)
	{

		
cout<<"Enter what: ";  
getline(cin, all_users[x].what); // Note: access the member what from struct mine


		cout<<"Enter fullname last name first: ";  
		getline(cin, name);

		cout<<"Enter Capital N or S: "; 
		getline(cin, letter);
		

		cout<<"Enter first integer: "; 
		getline(cin, integer);
	

		cout<<"Enter second integer: "; 
		getline(cin, integer2);
		cout <<endl;

		//prints to the file
		outfile<<name<<right<<setw(15)<<letter
			<<right<<setw(20)<<integer
			<<right<<setw(25)<<integer2
			<<right<<setw(30)<<"\n";
	}

	//close the output file 
		outfile.close();
		
		
		ifstream myfile ("test3.txt");
		//Dont Know how to read into and array of structure
		
		
		

	system("pause");
	return 0;
}
Topic archived. No new replies allowed.