Problem linking the array to txt file

Ok this is my txt file I am trying to get the last and first names (in that order) to show up in my program. The output that shows up is
1
2
3
4
5
6
7
8
9
10
2686760, 0
2686760, 1
2686760, 2
2686760, 3
2686760, 4
2686760, 5
2686760, 6
2686760, 7
2686760, 8
2686760, 9

This is my txt file.
Bob Saggot 89.02 70 75.4 60 99.9
Neal Young 90.5 90.2 92 94.6 99
Jean Simmons 100 97.2 85 40.5 100
John Doe 70 75 0 85.8 93.1
Jane Doe 80 88 84 80.3 89.9
Wayne Smith 90 99 92.2 94 98.7
Justin Bieber 10 11.2 29.9 20 40.5
Toby Keith 80.3 85.3 90.9 92.7 76
Alice Wonderland 100 100 100 100 100
Grim Reaper 0 60.8 40.3 20.9 90.9


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
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
  const int Num_Students = 10;
  const int Num_Scores = 5;
  char Names[Num_Students];
  char Scores[Num_Scores];
  int firstName, lastName, score;
  fstream Input;

  Input.open ("C:\\blah.txt");
  if (!Input)
    cout << "Error opening file.\n";
  else
  {
    for (firstName = 0; firstName < Num_Students; firstName++)
    {
        {
            cout << " " << (lastName)
                 << ", " << (firstName);
        }
        cout << endl;
    }
  }
    Input.close();

}
Last edited on
line 24: last name is declared but not defined
line 16: input ( is it ios::out or ios::in)? why dont you use it to print data?
all you do is open a file and close it.
Even using ios::in I'm stumped...

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
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
const int Num_Students = 10;
const int Num_Scores = 5;
char Names[Num_Students];
char Scores[Num_Scores];
int firstName, lastName, score;

fstream Input;

Input.open ("C:\\blah.txt", ios::in);
if (!Input)
cout << "Error opening file.\n";


cout << Input << endl;

Input.close();
system("PAUSE");
}


I am not sure what to do from here I want to at least read from the txt file but all I get back is 0x28fe68
Topic archived. No new replies allowed.