0

can somebody convert this line to c++? thanks

fscanf(in, "%s %s" ,student[x].name, student[x].num);
3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by cyther
1

Um, triumphost...fscanf() is for input, cout is for output. You probably mean cin:

std::cin >> student[x].name >> std::ws >> student[x].num;

Unfortunately, cin doesn't try to match literal data, but literal whitespace in the *scanf() format string is a special case. It means "extract and ignore any amount or type of whitespace". Conveniently enough, the ws modifier works the same way when used with cin.

0

thanks. but how about the in variable before "%s %s". how can you write it in c++?

1

thanks. but how about the in variable before "%s %s". how can you write it in c++?

Whoops, I see you're reading from a file (most likely). You'd need to open an fstream much the same way you open a FILE pointer using fopen():

ifstream in("myfile");

if (in)
{
    ...

    in >> student[x].name >> std::ws >> student[x].num;

    ...
}
0

thanks, and how can i write data at the end of text file?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.