[英]Expression must have integral or unscoped enum type
是否可以將兩個char const*
參數加在一起? 代碼應該看起來像這樣。 我需要c
像a
和b
一樣是char const
。 如果有人知道如何制作,請幫助我:) 提前致謝
char const *a = "something";
char const *b = " more";
char const *c = a + b;
如果您希望字符串像來自其他語言的對象一樣工作,請使用std::string
。
std::string a = "something";
std::string b = " more";
std::string c = a + b;
如果您需要將結果字符串傳遞給需要const char *
,您可以在字符串上調用c_str()
函數。
您應該有一個char
數組來創建連接結果:
char* result;
result = static_cast<char*>( calloc ( strlen( a) + strlen( b) + 1,
sizeof( char)));
strcpy( result, a); // copy string a into the result
strcat( result, b); // append b to the result
但是在 C++ 中你應該使用std::string
:
std::string a = "something";
std::string b = " more";
std::string result = a + b;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.