Stringstream into object
Dec 21, 2009 at 10:22am UTC
I have a file that shows the assigned number of a person, their name, correct answers and wrong answers on the form "4 Marie 30 8". I'm trying to read this into an object looking like this:
1 2 3 4 5 6 7
Keeptrack::Keeptrack(int a,string b,int c,int d)
{
assnum=a;
pername=b;
corrnum=c;
errnum=d;
}
And this is the actual code for the reading:
1 2 3 4 5 6 7 8 9 10
ifstream textlog("personalinfo.txt" );
istringstream ss;
getline(textlog,first);
ss.clear();
ss.str(first);
ss>>a>>b>>c>>d;
s1 = new Rum(a,b,c,d);
textlog.close();
first, a, b, c, and d are all declared locally.
Dec 21, 2009 at 10:59am UTC
Why don't you read directly from the file stream?
Dec 21, 2009 at 11:02am UTC
And I wish people would their variables proper names - it is starting to bug me now
Dec 21, 2009 at 11:12am UTC
What do you mean? Like _1, _2, _3, _4?
Dec 21, 2009 at 12:14pm UTC
Also, what's a Rum? I'm seeing a Keeptrack constructor, above.
Topic archived. No new replies allowed.