c++, problem with getline()

Status
Not open for further replies.

ibexpiotr

In Runtime
Messages
243
Location
New York
i have an assignment. i'm using a previously designed Card class.

the user inputs the data for each card object.((int1-4)suit,(int 1-13) rank and if its picked(bool))

then by using cards mem functions i output the values to the file
outfile << card.getSuit() << "\n"; ...etc

^^thats done in a while loop, keeps going till the user answers that he doesnt want to create any more cards


then there is another while loop for outputting from a file.
--> while(infile.peek() != EOF)

in there i wanned to use getline, but it gives me an error
error -could not find a match for getline/......

idk if my getline syntax is good - its getline(infile, s); i tried that..and also with specifying a delimiter

so i ended up using infile >> s;
but i realy wanna be able to use getline..

any help appreciated
 
Code:
#include<iostream>
using namespace std
.
.
.
.
.
.
.
ifstream Input
char record[100]
.
.
.
.
.
.
Input.getline(record,100)
 
how would u read int data from this file??

3
8
1

//first int 1-4 = suit
//second int 1-13 = rank
//third bool 0-1 = status

lets say my file looks liek tthis:
4
7
0
2
8
1


and i used this while loop to read in the data:

while(infile && (infile.peek() != EOF))
{


infile >> s;
infile >> r;
infile >> p;

..but it doesnt work correctly.. i always get rank to equal s, and i only get one card.(one card = 3lines)
 
Status
Not open for further replies.
Back
Top Bottom