excuse me as i am new to programming and trying to learn
i have searched through previous forum groups on this topic and i wish to seek the help of all tthe experts out there...
i wish to input a file into a class
i found this example
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
class job
{
string name;
int length, time;
string type;
char urgent;
public:
bool read(string &line)
{
istringstream iss(line);
return iss >> name >> length >> time >> type >> urgent;
}
void show()
{
cout << "name = " << name << '\n';
cout << "length = " << length << '\n';
cout << "time = " << time << '\n';
cout << "type = " << type << '\n';
cout << "urgent = " << urgent << '\n';
cout << endl;
}
};
int main()
{
ifstream iFile("input1.txt");
if ( iFile )
{
string line;
while ( getline(iFile, line) )
{
job myjob;
if ( myjob.read(line) )
{
myjob.show();
}
}
}
return 0;
}
but it only works if the format looks like this
BAK 90001 200 TXT N
CRSC 90010 150 TXT N
MARY 90011 140 FP N
CARL240 90050 300 FP N
LOW236 90052 150 FP N
where the space is the next variable
how would i manipulate this code if my stucture was on a per line basis as opposed to a space basis for the variable?
e.g.
bak
90001
200
txt
n
CRSC
90010
150
TXT
N
i need it to read the WHOLE line... as the name may or may not have a first and/or last name
thanks in adavance