Getline and Cout Issues

Hi, I'm a relative newbie to C++ and am studying in a 101 course right now. I'm having a real weird issue with my output. The goal is to read an entire line from an input file and have that read into a string. I'm not appearing to have any issues regarding that. The problem is that when I start to try to print these values to the screen, only the last value actually prints. For instance, if I were to have the following (ignore the output not being lined up properly for now)....:


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
#include <fstream>
#include <string>

using namespace std;

int main()
{

  string name, street, cityState, inFile;
  cout << "Enter file name: ";
  cin >> inFile;
  ifstream fileName;
  fileName.open(inFile.data());

  if (!fileName) {
    cout << "Cannot open file."  << endl;
    return 1;
  }
  cout << "Name                Street              City/State" << 
       endl;
  cout << "====                ======              ==========" << 
       endl;
  getline(fileName, name);
  while (fileName) {
    getline(fileName, street);
    getline(fileName, cityState);
   
    cout << name << street << cityState << endl;

    

    getline(fileName, name);
   }
  fileName.close();  
  
  return 0;

}
  
  


....Then only the variable cityState will be printed to the screen. Name and street are stored (apparently), but they don't get printed to the output screen.

Any help regarding this issue would be much appreciated!
Topic archived. No new replies allowed.