affiliatwebtips2018/01/31 04:50この場合、cには"2.78"という文字列を入れたいです。 さらに"rectangle"という文字列と連結したいのですが。 最終的に"rectangle2.78"という文字列を作成したいです。
episteme2018/01/31 04:54"2.78"はcharではない。文字列:const char*なら double d = 2.78; std::string str = "rectangle" + std::to_string(d); const char* p = str.c_str(); これで満足か?
affiliatwebtips2018/01/31 05:14すみません。先ほどの件、以下のようなエラーが出てしまいました。 エラー 1 error C2440: '初期化中' : 'const char *' から 'char *' に変換できません。 const char *からchar *への変換はできないでしょうか?
episteme2018/01/31 05:19十分な領域を確保し、strcpy()なりstring::copyでコピーせよ。 std::string str = "rectangle" + std::to_string(d); char p[N]; // 十分な大きさを確保しておくべし p[str.copy(p,str.size())] = '\0'; // あるいはフツーに strcpy(p, str.c_str());
episteme2018/01/31 05:23出来上がった "rectange2.78" をナニに使うんだ? const char* とすべきとこを char* で扱ってないか? だとしたらエラいムダだぞ?
episteme2018/01/31 05:49出来合いの関数が"絶対に"その引数を書き換えることがないなら char* p = const_cast<char*>(("rectangle" + std::to_string(2.78)).c_str());
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/31 04:50
2018/01/31 04:54
2018/01/31 05:06
2018/01/31 05:12
2018/01/31 05:14
2018/01/31 05:19
2018/01/31 05:21
2018/01/31 05:23
2018/01/31 05:39
2018/01/31 05:43
2018/01/31 05:49
2018/01/31 05:58
2018/01/31 06:00
2018/01/31 06:05
2018/01/31 06:11
2018/01/31 06:16
2018/01/31 06:20
2018/01/31 06:27