How do you get a file in C++?

后端 未结 4 1835
既然无缘
既然无缘 2021-01-22 03:53

So the teacher has posed this assignment:

You have been hired by the United Network Command for Law Enforcement, and you have been given files containing null cyphers yo

4条回答
  •  再見小時候
    2021-01-22 04:06

    To do file operations, you need the correct include:

    #include 
    

    Then, in your main function, you can open a file stream:

    ifstream inFile( "filename.txt", ios::in );
    

    or, for output:

    ofstream outFile( "filename.txt", ios::out );
    

    You can then use inFile as you would use cin, and outFile as you would use cout. To close the file when you are done:

    inFile.close();
    outFile.close();
    

提交回复
热议问题