I have a text file that reads like:
Mike
Thomas
100 Main Street
1009
456
199
John
Smith
200 Second Ave
etc......
I can get the values I need but when I try to get the address it only gives me up to the space. Is there a way to get the entire line as one string ?
Code is below ignore the commented out stuff I'm still working on it.
#include <cstdlib>
#include <iostream>
#include <string>
#include "person.h"
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
Person person1;
Student student1;
ifstream infile;
string name, lastname, add;
float point, credit, pointin, creditin;
int idnumin, count = 0;
//infile.open("stData.txt");
if (!infile)
{
cout << " The input file does not exist. "
<< " Program Terminates. " << endl;
system("pause");
return 1;
}
infile.open("stData.txt",ios::in);
// do
// {
// infile >> name;
while (!infile.eof())
{
infile >> name;
infile >> lastname;
infile >> add;
infile >> idnumin;
infile >> creditin;
infile >> pointin;
student1.setfirstname(name);
student1.setlastname(lastname);
student1.setaddress(add);
student1.setidnum(idnumin);
student1.setcredits(creditin);
student1.setpoints(pointin);
point = student1.getpoints();
credit = student1.getpoints();
student1.setgpa(credit,point);
student1.display();
// count ++;
}
infile.close();//while( count < 2 );
system("PAUSE");
return 0;
}
[code]Your code goes here[/code]
Try getline from string or iostream