can somebody convert this line to c++? thanks

fscanf(in, "%s %s" ,student[x].name, student[x].num);

Recommended Answers

All 5 Replies

std::cout<<student[x].name<< "    " <<student[x].num;

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.

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

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;

    ...
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.