0

1) I have this code

//... many code below
      std::basic_filebuf<char, std::char_traits<char> > streamIn;
      streamIn.open("file.txt", std::ios_base::trunc | std::ios_base::out);
      streamIn.sputn("Hello", 5);
//...

But in file.txt I see many many strange text. Not only Hello. This file also contaqins all my records from DB! I don't know why

2) Can I use std::basic_filebuf without file? Like std::basic_stringbuf

Solution for 1) is found

// ...
    std::basic_filebuf<char, std::char_traits<char> > streamIn;
    streamIn.open("file.txt", std::ios_base::out);
    streamIn.sputn(responce.c_str(), responce.size());
    streamIn.close();

    streamIn.open("file.txt", std::ios_base::in);
//...
4

1 回答 1

0

如此处所述,basic_filebuf 是与文件交互的 basic_streambuf。

所以不,我认为没有文件就不能使用它。

您可能想要做的是使用 basic_streambuf 代替,并且您可以控制是否希望它是文件(使用 basic_filebuf)或字符串(使用 basic_stringbuf)。

于 2012-04-18T07:39:58.907 回答