How do you open a file in C++?

后端 未结 9 1066
-上瘾入骨i
-上瘾入骨i 2021-02-01 15:41

I want to open a file for reading, the C++ way. I need to be able to do it for:

  • text files, which would involve some sort of read line function.

9条回答
  •  眼角桃花
    2021-02-01 16:13

    Follow the steps,

    1. Include Header files or name space to access File class.
    2. Make File class object Depending on your IDE platform ( i.e, CFile,QFile,fstream).
    3. Now you can easily find that class methods to open/read/close/getline or else of any file.
    CFile/QFile/ifstream m_file;
    m_file.Open(path,Other parameter/mood to open file);
    

    For reading file you have to make buffer or string to save data and you can pass that variable in read() method.

提交回复
热议问题