ぺぺです。C++の初心者なので、いろいろ困っています。
どなたかご教授ください。よろしくお願いします。
OS:Linux Enterprise AS 4.0
string変数に、charポインタとconst charを加算した値を代入すると、コンパイルエラーが発生します。このプログラムって無効なのでしょうか?
char* a="abc";
string b;
b = "def" + a; // コンパイルエラー
↓エラー内容
invalid operands of types `const char[4]' and `char*' to binary `operator+'
> 無効なのでしょうか
です。
b = std::string( "def" ) + a;
または
b = "def";
b += a;
として、一度std::stringに入れれば、std::stringのoperator+でできます。
Buleさんありがとうございます。m(_ _)m
解決いたしました。
ツイート | ![]() |