string変数にcharポインタとchar constの加算

解決


ぺぺ  2005-11-04 11:02:34  No: 59475  IP: 192.*.*.*

ぺぺです。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+'

編集 削除
Blue  2005-11-04 11:07:20  No: 59476  IP: 192.*.*.*

> 無効なのでしょうか
です。
b = std::string( "def" ) + a;
または
b = "def";
b += a;
として、一度std::stringに入れれば、std::stringのoperator+でできます。

編集 削除
ぺぺ  2005-11-04 11:17:41  No: 59477  IP: 192.*.*.*

Buleさんありがとうございます。m(_ _)m
解決いたしました。

編集 削除