How do you open a file in C++?

后端 未结 9 868
-上瘾入骨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 15:54

    #include 
    #include 
    using namespace std;
    
    int main () {
      ofstream file;
      file.open ("codebind.txt");
      file << "Please writr this text to a file.\n this text is written using C++\n";
      file.close();
      return 0;
    }
    

提交回复
热议问题