楽しさと経験のために、とのBlobby Volley 2 1.0(Linux)のソースコードを変更しています。std :: ostreamはconst char配列を出力できませんか?
まあ... は、ソースコードを変更していますが、私はコンパイルするためのプログラムを手に入れることさえできません。 (?悲しいことではありません)
ここでエラーが発生するコードです:グラム++ 5.4.0でこれをコンパイルしようとすると
std::ostream& operator<<(std::ostream& stream, const ServerInfo& val) {
return stream << val.name << " (" << val.hostname << ":" << val.port << ")";
}
は、以下の(単純化出力できます - 元の出力を
std::ostream& operator<<(std::ostream& stream, const ServerInfo& val) {
stream << "hello"; //can't get simpler than this, right?
return stream;
}
:私はこれまでのコードを簡素化
error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream}’ and ‘const char [32]’)
return stream << val.name << " (" << val.hostname << ":" << val.port << ")";
:〜443行)エラーメッセージです
と
error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream}’ and ‘const char [6]’)
stream << "hello";
それはこのようになります呼び出すコードだ:私が最も驚くべき見つける事は、我々はすべてstd::cout
およびその同類がchar
配列を扱うことができることを知っているということです
std::cout << "duplicate server entry\n";
std::cout << info << "\n"; //it's called here
を。例えば
、滞りなく動作します
#include <iostream>
#include <string>
int main() {
const char a[6] = "hello";
std::cout << a << std::endl; //No problem here!
return 0;
}
。
ああ、もう1つ。
私は<string>
が含まれている場合、これは動作します:
std::ostream& operator<<(std::ostream& stream, const ServerInfo& val) {
stream << std::string("hello");
return stream;
}
誰もが私が欠けているものを知っていますか?
PS:私は「didnのなぜあなたは不思議に思っている場合:はここpastebin of the errors.
PPSです:
/* header include */
#include "NetworkMessage.h"
/* includes */
#include <cstring>
#include "UserConfig.h"
#include "SpeedController.h"
PPS:ここでは、要求されたヘッダですstd::ostream
が定義されていないというエラーが表示された場合は、3番目のパラグラップを確認してくださいサムの答えのh。
ここに記載されているものに加えて、完全なエラーログを投稿できますか?そこに重要なことがあるかもしれません。 – templatetypedef
@templatetypedef:あなたはそれをすべて肯定していますか? –
通常は起こらないエラーを報告していますので、他にも何か問題があると思われます。あ、はい! :-) – templatetypedef