what is wrong with this program?

后端 未结 4 1372
时光说笑
时光说笑 2021-01-27 04:54
#include 
#include 
#include 

using namespace std;

int main() {
    string x;
    getline(cin,x);
    ofstream o(\"f:/demo         


        
4条回答
  •  无人共我
    2021-01-27 05:24

    You're passing the object's address to write into the file, whereas the original content lies somewhere else, pointed to by one of its internal pointers.

    Try this:

    string x;
    getline(cin,x);
    ofstream o("D:/tester.txt");
    o << x;
    // or
    // o.write( x.c_str() , x.length());
    

提交回复
热议问题