I have been reading older C programs to try and understand how to convert them to C++. One particular line of code still confuses me however.

fscanf(fin, "%d", &n)

I understand that fscanf reads from the stream (the file pointed to by fin), it reads the data which will be decimals (%d), and stores the data in n. Is this correct? Also, what would be the C++ equivalent of this. I have read the documentation of fscanf at www.cplusplus.com but I just need clarification.

Recommended Answers

All 2 Replies

Its a lot simplier in c++

ifstream in("myfile");
int n;
in >> n;

Thanks for the help.

Be a part of the DaniWeb community

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