Strings in file I/O/

closed account (LzwkoG1T)
So I'm trying to do a basic program which takes in id nos. and names and store it in a file.

the problem: ">> does not have any matching operands"

1
2
3
4
   int id;
   string name;
   while( cin >> id >> name )
     fileobj << id  << " " << name;



I use Microsoft Visual Studio 2010
Last edited on
why are you inputting to values with one cin ?

try this :
1
2
3
4
while ( cin >> id ) {
    cin >> name
    fileobj << id << " " << name;
}
sounds like a missing #include <string>

@nevermore28 your code uses the variable name without checking if stream extraction into name succeeded, while OP makes that check
Last edited on
closed account (LzwkoG1T)
Thanks for the help Cubbi. Fixed it by including <string>
@Cubbi

Oh, i see i didn't know you can input 2 values using only one cin :0
Topic archived. No new replies allowed.