草庐IT

SOME_VARIABLE_STRING

全部标签

c++ - 从 std::stringstream 传递 std::string 引用作为参数

我正在使用std::stringstream构造一个字符串,然后尝试将完成的字符串作为对函数的引用传递,该函数将std::string&作为参数。我在GCC上遇到编译错误:../src/so.cpp:22:21:error:invalidinitializationofnon-constreferenceoftype‘std::string&{akastd::basic_string&}’fromanrvalueoftype‘std::basic_stringstream::__string_type{akastd::basic_string}’../src/so.cpp:12:6:e

c++ - std::condition_variable wait() 和 notify_one() 同步

前言:我在这里看到过类似的问题,但似乎没有一个能回答我的问题。是否有可靠的方法来确保消费者线程中的wait()方法在生产者线程的第一个notify_one()调用之前被调用?即使在消费者线程中使用unique_lock,也有可能生产者线程会先运行,锁定互斥量并在消费者调用之前调用notify()wait(),因此,我的应用程序将缺少第一个notify()调用。编辑:感谢您的所有回答,它们确实帮助了我。我的问题是这个消费者循环中的第一个wait-notify():while(!timeToQuit){gdcv.wait(gdcondlock);gdlock.lock();//spurio

c++ - 采用 `std::string` 的显式构造函数得到 `char*` 并且工作正常

将StringBuilder构造函数标记为显式我想我不能传入char*但似乎我可以,因为它编译得很好。classStringBuilder{public://StringBuilder(constchar*);explicitStringBuilder(std::strings){}};intmain(){StringBuilders1("hello");StringBuilders2(std::string("hello"));}http://cpp.sh/6uomq 最佳答案 basic_string采用字符指针的构造函数不是e

c++ - write_some 与 write - boost asio

当write_some可能无法将所有数据传输到对等端时,为什么有人要使用它?来自boostwrite_some文档Thewrite_someoperationmaynottransmitallofthedatatothepeer.Considerusingthewritefunctionifyouneedtoensurethatalldataiswrittenbeforetheblockingoperationcompletes.write_some方法在boost中有write方法的相关性是什么?我浏览了boostwrite_some文档,我猜不出什么。

c++ - 由于对具有 std::string 的方法的 undefined reference ,链接 webrtc-native 时出错

我正在尝试构建webrtc版本62,使用以下内容1.gitcheckout-bbranch62refs/remotes/branch-heads/622.gngenout_release_62/x64/Debug--args="rtc_include_tests=falsertc_use_h264=falseuse_rtti=trueis_component_build=falseenable_iterator_debugging=falseenable_nacl=falsetarget_os=\"linux\"target_cpu=\"x64\"is_debug=true"3.nin

c++ - std::string erase 删除最后一个字母

我想为游戏输入一些内容,然后在按退格键后删除字符串中的最后一个字母。我不确定是否应该执行text.end-1或+1到end来执行此操作:if(GetAsyncKeyState(VK_BACK))text.erase(text.end-1,text.end); 最佳答案 std::string实际上有一个pop_back()方法!所以你可以这样做:if(GetAsyncKeyState(VK_BACK)&&!text.empty()){text.pop_back();} 关于c++-std

c++ - 如何在编译时解析静态常量 std::string?

我的C++代码中有一些带有绑定(bind)的SQL查询,这些查询是staticconststd::string,因为这些查询很复杂,所以很容易在某些细节上出错。我想在编译时做一些非常基本的检查,例如计算逗号或:字符的数量。 最佳答案 你不能。staticconststd::string在编译时不存在。constexpr函数可以使用字符串文字,但不能使用std::string对象。 关于c++-如何在编译时解析静态常量std::string?,我们在StackOverflow上找到一个类似

c++ - 如何在 QLineEdit 中使用 std::string?

我有以下问题。我正在尝试将我编写的大型代码与Qt界面集成。我的一些函数返回std::string。我没有成功地让QLineEdit::setText接受它们(其他返回char的函数不会给我带来问题)。我该怎么办?谢谢!朱塞佩 最佳答案 试试这个:std::stringa="aaa";lineEdit->setText(QString::fromStdString(a));您将需要支持STL的Qt。 关于c++-如何在QLineEdit中使用std::string?,我们在StackOve

c++ - 可以在构造函数中分配 std::string 吗?

我有以下构造函数:TCPConnector(int32_tfd,stringip,uint16_tport,vector&protocolChain,constVariant&customParameters):IOHandler(fd,IOHT_TCP_CONNECTOR){_ip=ip;_port=port;_protocolChain=protocolChain;_closeSocket=true;_customParameters=customParameters;}我想知道是否可以在构造函数中安全地分配一个字符串(即_ip)而无需显式初始化它? 最

java - 如何在 JNI 中访问从 C++ 返回 java.lang.String 的 Java 方法的返回值?

我正在尝试从C++调用的Java方法传回一个字符串。我无法找出应该调用什么JNI函数来访问该方法并返回一个jstring值。我的代码如下:C++部分main(){jclasscls;jmethodIDmid;jstringrv;/**...omittedcode...*/cls=env->FindClass("ClassifierWrapper");mid=env->GetMethodID(cls,"getString","()Ljava/lang/String");rv=env->CallStaticMethod(cls,mid,0);constchar*strReturn=env-