开发者

What is the c++ translation for 'textscan' function from Matlab?

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 co开发者_JS百科de into C++. Thank you very much.


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 textscan reads from files or strings. C and C++ have different mechanisms for that.

To read from a file :

In C, you should use the FILE object and its associated functions (fopen, fgets ...) from the header file : stdio.h.

In C++, you should use std::ifstream from 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.h header.

In C++, the better way is to use the std::istringstream class from the sstream header file.


It is fscanf. You will need to #include <stdio.h> and open FILE objects with fopen to use it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜