草庐IT

string_with_shortcodes

全部标签

.NET System::String 到存储在 char* 中的 UTF8 字节

我正在将一些非托管C++代码包装到.NET项目中。为此,我需要将System::String转换为存储在char*中的UTF8字节。我不确定这是否是最好的或什至是正确的方法,如果有人可以看一下并提供反馈,我将不胜感激。谢谢,/大卫//CopyintoblankVisualStudioC++/CLRcommandlinesolution.#include"stdafx.h"#includeusingnamespaceSystem;usingnamespaceSystem::Text;usingnamespaceSystem::Runtime::InteropServices;//Test

RabbitMQ(十二)Cannot deserialize value of type `java.lang.String` from Object value 报错整理

目录1.核心报错内容:2.完整报错内容:3.报错原因:4.解决方案:消息接收类型错误1.核心报错内容:Cannotdeserializevalueoftypejava.lang.StringfromObjectvalue(tokenJsonToken.START_OBJECT)2.完整报错内容:org.springframework.amqp.rabbit.listener.exception.FatalListenerExecutionException:Illegalnullidinmessage.Failedtomanageretryformessage:(Body:'[B@7f8bf9

C++ 设计 : functions with boolean options

我有一个关于C++中“良好设计实践”的问题。我正在用C++11编写一个数字库,我使用了很多元编程和基于模板的技术。但我有一个非常基本的问题:考虑一个函数,它可以有两个非常接近的行为,除了一个可以由boolean标志激活的选项。我只考虑一个可以由开发人员设置/取消设置的标志,而不是一个可以在运行时设置/取消设置的标志。设计有3种可能性:1)编写两个在名称中带有显式选项的函数:myFunctionFlag1(...);myFunctionFlag2(...);2)使用模板参数:templatemyFunction(...);3)使用可变参数:myFunction(...,constbool

c++ - 如何检查 std::string 是否确实是整数?

以下代码将std::string转换为int,问题在于它无法辨别是真正的整数还是随机字符串。有没有系统的方法来处理这样的问题?#include#include#includeintmain(){std::stringstr="H";intint_value;std::istringstreamss(str);ss>>int_value;std::cout编辑:这是我喜欢的解决方案,因为它非常简约和优雅!它不适用于负数,但无论如何我只需要正数。#include#include#includeintmain(){std::stringstr="2147483647";intint_valu

c++ - 将文字分配给 std::u16string 或 std::u32string

据我所知,我可以将一个字面值赋给一个字符串:std::strings="good";std::wstrings=L"good";我如何分配给一个std::u16strings=std::u32strings= 最佳答案 您可以阅读有关C++字符串文字的信息here.特别是对于UTF-16文字,您使用小写字母u作为前缀:u16strings=u"...";对于UTF-32文字,您可以使用大写字母U作为前缀:u32strings=U"..."; 关于c++-将文字分配给std::u16str

c++ - Qt 应用程序 : build with different Qt versions 的 CI

我使用Travis-CI为我的简单Qt应用程序进行持续集成。我的.travis.yml文件看起来像这样(基于thisgist):language:cppbefore_install:-sudoadd-apt-repository--yesppa:ubuntu-sdk-team/ppa-sudoapt-getupdate-qq-sudoapt-getinstall-qqg++qt4-qmakelibqt4-devqt5-qmakeqtbase5-devscript:-qmake-qt=qt4-v-qmake-qt=qt4-make-make-kcheck-makeclean-qmake-

c++ - 如何在不使用 to_string 或 stoi 的情况下将 int 转换为 C++11 中的字符串?

我知道这听起来很愚蠢,但我在Windows7上使用MinGW32,并且“to_string未在此范围内声明。”It'sanactualGCCBug,我关注了theseinstructions他们没有工作。那么,如何在不使用to_string或stoi的情况下将int转换为C++11中的字符串?(另外,我启用了-std=c++11标志)。 最佳答案 这不是最快的方法,但您可以这样做:#include#include#includetemplatestd::stringstringulate(ValueTypev){std::ostri

c++ - std::string 类成员应该是指针吗?

为什么/为什么不呢?假设我有一个类,它在构造函数中接收一个字符串并将其存储。这个类成员应该是一个指针,还是只是一个值?classX{X(conststd::string&s):s(s){}conststd::strings;};或者...classX{X(conststd::string*s):s(s){}conststd::string*s;};如果我要存储原始类型,我会复制一份。如果要存储对象,我会使用指针。我觉得我想要复制那个字符串,但我不知道什么时候决定。我应该复制vector吗?套?map?整个JSON文件...?编辑:听起来我需要阅读移动语义。但无论如何,我想让我的问题更具

c++ - 可以在构造时修改命名的 std::string 吗?

有谁知道为什么注释行编译失败但未注释行没问题?#includeintmain(){//std::stringfoo("hello").erase(2);//Thisdoesn'tcompile...std::string("hello").erase(2);//...butthisdoes.}包含注释行会导致此错误:main.cpp:Infunction‘intmain()’:main.cpp:5:error:expected‘,’or‘;’before‘.’token谁能解释一下在构造匿名std::string对象时修改匿名对象和命名对象的规则是什么? 最

c++ - 变长数组 : How to create a buffer with variable size in C++

我目前正在编写一个移动平均线类。目标是在创建Running_Average类的新对象时能够将缓冲区大小指定为构造函数的一部分。#include#include"Complex.h"#include#include#include#includeusingnamespacestd;classRunning_Average{public:doublesum=0;doubleaverage=0;inti;doubleAverage(void);//MemberfunctionsdeclarationvoidAddSample(double);Running_Average(int);};Ru