草庐IT

string.format

全部标签

c++ - 如何将 tr1/array 转换为 std::string?

我想知道如何投std::tr1::array到std::string?编译器总是报错,我试过了std::tr1::arraysss;string(sss);stringasd(sss);两者都有效... 最佳答案 unsignedchar让这变得棘手。如果您知道您的系统使用2s补码1字节8位unsignedchar和char,以及从unsignedchar到char的隐式转换做你想做的(这些并不总是正确的!),并且你的数组缓冲区是null终止的(即,第一个0之后的字符应该被丢弃),这个函数有效:templatestd::string

解决:OpenCV: FFMPEG: tag 0x44495658/‘XVID‘ is not supported with codec id 12 and format ‘mp4 / MP4

解决:OpenCV:FFMPEG:tag0x44495658/‘XVID’isnotsupportedwithcodecid12andformat'mp4/MP4文章目录解决:OpenCV:FFMPEG:tag0x44495658/'XVID'isnotsupportedwithcodecid12andformat'mp4/MP4背景报错问题报错翻译代码如下fourcc报错原因解决方法今天的分享就到此结束了背景在使用之前的代码利用python的opencv包把图片合并为视频(mp4格式)的时候,报错:OpenCV:FFMPEG:tag0x44495658/‘XVID’isnotsupporte

c++ - 从 std::string 中提取整数

我正在编写简单的OBJ加载器,我遇到了下一个问题-我必须从下一个std::string中提取整数:fv0/vt0/vn0v1/vt1/vn0...vk/vtk/vnk其中vk、vtk、vnk都是int值,/和值之间没有空格组与组之间只有一个空格。由于文件可能非常大,而且这种类型的行可能出现超过100000次,我需要一种有效的方法来从像这样的字符串中提取整数。编辑:正如Jesse所问,这是我目前的方法(我假设数据格式正确!):intp,t,n;constchar*l=line.c_str()+2;for(intvIndex=0;l&&sscanf(l,"%d/%d/%d",&p,&t,&

c++ - 'unused' 的初始化被 'goto label' 跳过 - 为什么我为 std::string 而不是为 int 获取它?

我在某些代码中遇到了这个错误,经过一些试验后我偶然发现了这个怪异之处——我为std::string得到了它,但没有为int得到它。对于std::string我得到errorC2362:initializationof'unused'isskippedby'gotolabel':{gotolabel;std::stringunused;label:;}对于int我没有收到任何错误,但是:{gotolabel;intunused=10;label:;}为什么不同?是因为std::string有一个非平凡的析构函数吗? 最佳答案 这包含在

c++ - 解析 yyyy-MM-dd HH :mm:ss date time string?

我有一个来自mysql的日期时间。我需要提取每个部分:intyear;intmonth;intday;inthour;intmin;intsec;例子:2014-06-1020:05:57对于每个组件,是否有比通过stringstream运行它更简单的方法?(请不要使用boost或c++11解决方案)。谢谢 最佳答案 sscanf()可能是最直接的选择。它是一个C库函数,因此纯粹主义者可能不赞成它。这是一个例子:intyear;intmonth;intday;inthour;intmin;intsec;constchar*str="

c++ - scanf 与 cin : string as integer processing

我有一个输入字符串“0100”为什么scanf("%i",&n);返回64而cin>>n;给我100?为什么cin以十进制值思考,而scanf以八进制值思考? 最佳答案 Fortheispecifier:  Anynumberofdigits,optionallyprecededbyasign(+or-).Decimaldigitsassumedbydefault(0-9),buta0prefixintroducesoctaldigits(0-7),and0xintroduceshexadecimaldigits(0-f).-sca

c++ - boost::filesystem::path::string() 输出的奇怪行为

pf.string()输出似乎有一些奇怪的行为,其中pf是用p.filename()生成的,其中p是boost::filesystem::path类型,由charconst*或std::string构造。这是代码段:#includenamespacefs=boost::filesystem;intmain(intargc,char**argv){fs::pathp(argv[0]);//orfs::pathp((std::string(argv[0])));fs::path&&pf=p.filename();//orfs::pathpf=p.filename();std::string

Flink Format系列(2)-CSV

Flink的csv格式支持读和写csv格式的数据,只需要指定'format'='csv',下面以kafka为例。CREATETABLEuser_behavior(user_idBIGINT,item_idBIGINT,category_idBIGINT,behaviorSTRING,tsTIMESTAMP(3))WITH('connector'='kafka','topic'='user_behavior','properties.bootstrap.servers'='localhost:9092','properties.group.id'='testGroup','format'='cs

c++ - 错误 : no matching function for call to ‘to_string(std::basic_string<char>&)’

即使在模板中我可以有任何类型,函数to_string对基本字符串不起作用:例如:std::stringstr("mystring");my_class(str);用这个仿函数定义:templatevoidoperator()(valuetypevalue){...private_string_field=std::to_string(value);不起作用。这是错误:error:nomatchingfunctionforcallto‘to_string(std::basic_string&)’避免它的最佳方法是什么。事先,我要求避免仅仅因为一些常见的关键字就链接到不相关的问题。

c++ - "no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’“

我正在尝试使用std::async创建线程,但我不断收到错误“没有匹配函数调用‘async(std::launch,,std::string&)’”在行上ConnectFuture=std::async(std::launch::async,Connect_T,ip);这是产生这种行为的代码:#includeclasslibWrapper{public:voidConnect(std::stringip);voidConnect_T(std::stringip);private:std::futureConnectFuture;};voidlibWrapper::Connect(std