草庐IT

basic_streambuf

全部标签

c++ - 我什么时候调用 boost::asio::streambuf::consume() 和 boost::asio::streambuf::commit()?

我试图理解boost::asio::streambuf::consume()和boost::asio::streambuf::commit()调用.在文档中,我们有示例,boost::asio::streambufb;std::ostreamos(&b);os和boost::asio::streambufb;//reserve512bytesinoutputsequenceboost::asio::streambuf::mutable_buffers_typebufs=b.prepare(512);size_tn=sock.receive(bufs);//receiveddatais"

c++ - 是否有将主​​机字节顺序转换为网络字节顺序的 std::streambuf 版本?

有没有std::streambuf-将多字节值转换为网络字节顺序的类似机制?特别是,BoostAsio是否提供这样的原语?这是我希望流缓冲区执行的操作的示例:uint64_tx=42ull;network_streambufb1;std::ostreamos(&b1);os>y;//ntohll编辑:答案表明这是思考问题的错误方式:流缓冲区只是提供对字符序列的访问,它们的工作不是执行格式化I/O或转换。我可能会实现一个小型缓冲类,为operator提供必要的重载。和operator>>执行转换。 最佳答案 不,我会告诉你原因。ist

c++ - 如何将 std::basic_string 类型转换为 char 类型的数组?

运行此代码时出现以下错误:syslog(LOG_ERR|LOG_USER,"%s",errorString);cannotconvert‘conststring{akaconststd::basic_string}’to‘constchar*’for>argument‘2’to‘voidsyslog(int,constchar*,...)’inServer.cpp/PeCounterline478C/C++Problem我正在守护程序,当使用cout输出到stdio时,errorString值打印得很好,但在使用syslog调用时不会打印。将std::basic_string(char

C++ "error: passing ' const std::map<int, std::basic_string<char>>' as ' this' argument of ..."

使用以下代码(为简洁起见摘录):颜色.h:classcolor{public:color();enumcolorType{black,blue,green,cyan,red,magenta,brown,lightgray,nocolor};colorTypegetColorType();voidsetColorType(colorTypecColortype);stringgetColorText()const;private:colorTypecColortype=nocolor;mapcolors={{black,"black"},{blue,"blue"},{green,"gre

c++ - 继承自 std::basic_streambuf 以写入套接字

我想编写一个我自己的日志记录库,为日志条目发送到的任何地方提供抽象。C++的IO库已经通过std::stringstream和std::fstream提供了这种抽象。我还希望能够从套接字读取/向套接字写入。我读到扩展标准库的正确方法是继承std::basic_streambuf。我不明白的是,如果像std::basic_filebuf那样从std::basic_streambuf继承,那么哪里需要std::ifsream、std::ofstream和std::fstream类?我不能只用std::basic_streambuf的子类实例替换某些流的缓冲区,它输出我想要的地方吗?到目前为

c++ - 不能为 std::basic_string<T> foo = "foo"推导出 T = char?

问题:在下面的代码中,第一个示例的模板参数类型推导似乎失败了,但第二个示例却没有。我不明白为什么第一个样本无法推断出T=char.我会认为T从"foo"转换时可以推导出至std::bacis_string,但即使这不起作用,我也提供了第二个函数参数,我认为它会明确约束T至char.为什么它会失败?Doesnotwork:#include#includetemplatevoidprint(conststd::basic_string&a,conststd::basic_string&b){std::cout错误:string.cpp:14:5:error:nomatchingfuncti

c++ - 无法访问类 'std::basic_ios<_Elem,_Traits>' 中声明的私有(private)成员

这个特定方法有问题,不知道如何解决!我得到的错误是上面的:"errorC2248:'std::basic_ios::basic_ios':cannotaccessprivatememberdeclaredinclass'std::basic_ios'C:\ProgramFiles\MicrosoftVisualStudio10.0\VC\include\ostream604"我的方法是:ostreamoperator在标题中:friendstd::ostreamoperator关于如何解决这个问题的任何想法?我认为这与通过引用而不是值传递有关...但我有点困惑!

c++ - 理解错误 "terminate called after throwing an instance of ' std::length_error' what(): basic_string::_S_create Aborted (core dumped)"

所以这是我的错误:terminatecalledafterthrowinganinstanceof'std::length_error'what():basic_string::_S_createAborted(coredumped)这是我的代码://CoderemovedstringgenerateSong(stringlist[],intnum){//Coderemoved//Coderemovedfor(i=0;i我只想知道该错误的含义,以便我知道如何修复它。我看到很多帖子都有类似的错误,但没有完全相同的。从字面上看,我才刚刚开始使用C++,而这些答案对我目前所学的知识都没有任何

c++ - basic_string::_S_construct null 无效

我正在从命令行读取输入文件。intmain(intargc,char**argv){ScenemyScene;stringfilename=argv[1];myScene=Parser(filename);...}在另一个文件中,我使用了像这样declerated的解析器函数;SceneParser(stringfilename){stringline;ifstreammyfile(filename.c_str());...returnscene;}我收到错误;在抛出“std::logic_error”的实例后终止调用what():basic_string::_S_constructn

windows - 在visual basic中模拟windowskey+L?

我想在VisualBasic中模拟Windows键+L(锁定控制台的快捷方式)并将其绑定(bind)到一个函数。所以当这个函数被调用时它会锁定控制台。我可以这样做吗? 最佳答案 模拟热键是错误的做法。您需要做的就是调用LockWorkStationfunction.这与按Ctrl+Alt+Del并选择“锁定工作站”或使用Win的结果相同>+L热键,除了您可以通过代码以编程方式完成。要从VB应用程序调用此函数,您需要编写一个声明,如下所示:PrivateDeclareFunctionLockWorkStationLib"user32.