ofstream doesn't write buffer to file

前端 未结 5 1408
耶瑟儿~
耶瑟儿~ 2021-01-24 06:56

I\'m trying to write the contents of buf pointer to the file created by ofstream.

For some reason the file is empty, however the contents of buf is never empty... What

5条回答
  •  感动是毒
    2021-01-24 07:34

    Is your stream opened before writing on it ? Could be anything from not-enough disk space to unsufficient permissions.

    Also you may have an error:

    ofstr << *buf;
    

    Should be something like:

    ofstr << buf;
    

    Since buf is a char*, *buf gives a char, not a char*.

    This is where using std::string instead of raw buffers/pointers makes sense ;)

提交回复
热议问题