What is a simple translation in code for ‘textscan’ from matlab into C or C++?
I am using Ubuntu and I am trying to translate a Matlab code into C++.
Thank you very much.
What is a simple translation in code for ‘textscan’ from matlab into C or
Share
First, the answer is not the same if you’re using C or if you’re using C++. These are different programming languages.
Matlab is a much higher-level language than C and C++. In Matlab
textscanreads from files or strings. C and C++ have different mechanisms for that.To read from a file :
In C, you should use the
FILEobject and its associated functions (fopen, fgets …) from the header file :stdio.h.In C++, you should use
std::ifstreamfrom the<fstream>header file. For formatted input use the>>operator.To read from a string :
In C, you might want to look at the functions in the
string.hheader.In C++, the better way is to use the
std::istringstreamclass from thesstreamheader file.