what is wrong with this program?

后端 未结 4 1364
时光说笑
时光说笑 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:04

    You get exactly what you write: the binary raw value of a pointer to char...

    #include 
    #include 
    #include 
    using namespace std;
    
    int main()
    {
        string x;
        getline(cin,x);
        ofstream o("tester.txt");
        o << x;
        o.close();
    }
    

    If you insist on writing a buffer directly, you can use

    o.write(x.c_str(), x.size());
    

    PS A little attention to code formatting unclouds the mind

提交回复
热议问题