Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C+中的Concat字符串+;(STL)_C++_String_Stl - Fatal编程技术网

C++ C+中的Concat字符串+;(STL)

C++ C+中的Concat字符串+;(STL),c++,string,stl,C++,String,Stl,我有这样的代码 string xml_path(conf("CONFIG")); xml_path+=FILE_NAME; 在哪里,, conf函数返回char*,文件名为const char* 我想把它合并成一行,就像 xml_path(conf("CONFIG")).append(FILE_NAME) 我该怎么做 有什么建议吗 const char * f = "foo"; char * b = "bar"; string s = string( f ) + b; 请注意,您不能

我有这样的代码

string xml_path(conf("CONFIG"));

xml_path+=FILE_NAME;
在哪里,, conf函数返回
char*
,文件名为
const char*

我想把它合并成一行,就像

xml_path(conf("CONFIG")).append(FILE_NAME) 
我该怎么做

有什么建议吗

const char * f = "foo";
char * b = "bar";

string s = string( f ) + b;
请注意,您不能使用append(-0),因为INVOLVED的两个字符串都不是std:;字符串。如果确实要追加,则必须是两个阶段的过程:

string s ( f );
s.append( b );

应该这样做。

或者,如果要格式化不同类型的变量,请使用ostringstream

例如

std::ostringstream oss;
INTA=2;
char*s=“sometext”;

oss关于一行的问题:

string xml_path = string(conf("CONFIG")) + string(FILE_NAME);

(我假设
xml\u path
是变量的名称,而不是我不知道的库中的某种调用)。

每个人都忽略了一个事实,即您要求的是一行解决方案。(但您为什么要这样做呢?)假设我要包含5个字符串,那么我就可以这样做。append().append()我不需要像在java StringBuffer obj=newStringBuffer(“foobar”).append(“foo”).append(“bar”);
std::ostringstream oss; 
int a = 2; 
char *s = "sometext"; 
oss<<s<<a<<endl; 
cout<<oss.str(); // will output "sometext2"
string xml_path = string(conf("CONFIG")) + string(FILE_NAME);