How do you open a file in C++?

后端 未结 9 853
-上瘾入骨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:58

    **#include //to use file
    #include  //to use getline
    using namespace std;
    int main(){
    ifstream file;
    string str;
    file.open("path the file" , ios::binary | ios::in);
    while(true){
       getline(file , str);
       if(file.fail())
           break;
       cout<

提交回复
热议问题