Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » c++, problem with getline()
Closed Thread
Old 10-12-2005, 06:56 PM   #1 (permalink)
ibexpiotr's Avatar
 
True Techie

Join Date: Nov 2003

Posts: 197

ibexpiotr is on a distinguished road

Send a message via AIM to ibexpiotr
Default c++, problem with getline()

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
ibexpiotr is offline  
Old 10-12-2005, 11:12 PM   #2 (permalink)
 
Super Techie

Join Date: Jun 2005

Posts: 274

mgoldb2

Default

Code:
#include<iostream>
using namespace std
.
.
.
.
.
.
.
ifstream Input
char record[100]
.
.
.
.
.
.
Input.getline(record,100)

mgoldb2 is offline  
Old 10-13-2005, 04:32 PM   #3 (permalink)
ibexpiotr's Avatar
 
True Techie

Join Date: Nov 2003

Posts: 197

ibexpiotr is on a distinguished road

Send a message via AIM to ibexpiotr
Default

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)
ibexpiotr is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On