2011-03-15 8 views
0
string mesag=""; 
mesag="aDoubleArray value at 0------->"<<aDoubleArray[0]<<" aDoubleArray value at 1 is "<<aDoubleArray[1]; 
addLog(AMR_LT_WARN, mesag);// this part not working 
addLog(AMR_LT_WARN, "this works well"); 

「ダブル」型があります。違法、右オペランドの型がdoubleです。エラーC2297:「<<」:「< <」:違法、右オペランドは、私はちょうどファイルをログに記録するaDoubleArray値を印刷したいが、それは エラーがスローC2297 C++についてanythng知らない

答えて

0

あなたは、次のような何かをする必要があります。

char message[100]; 
sprintf(message, "aDoubleArray value at 0-------> %g aDoubleArray value at 1 is %g", aDoubleArray[0], aDoubleArray[1]); 

std::string mesag(message); 
addLog(AMR_LT_WARN, mesag);// this part not working 
addLog(AMR_LT_WARN, "this works well"); 
+0

おそらくiostreamsが望ましいでしょう。%dのようなタイプエラーは避けられますが、これはダブルではありません。 – dalle

+0

私は上記で試しましたが、以下のエラーが発生しました:C2664: 'addLog':paramを変換できません eter 2 'class std :: basic_string 、class std :: allocator >' to 'const char * ' [exec]この変換を実行できるユーザー定義変換演算子はありません。または演算子を呼び出すことができません。 – Gopal

+0

これを 'addLog(AMR_LT_WARN、mesag.c_str());に変更してください。 – Aamir

3

これを行うには、文字列ストリームを使用する必要があります。 sstreamを含めて、あなたのような何かを行うことができます。

#include <iostream> 
#include <sstream> 
int main(void) { 
    double d = 3.14159;   // this is the double. 
    std::stringstream ss;  // this is the stream. 
    ss << "Double is " << d; // Send normal output to stream. 
    std::cout << "["   // Use str() to get underlying string. 
       << ss.str() 
       << "]" 
       << std::endl; 
    return 0; 
} 

これは"Double is 3.14159"と角括弧で囲まれた出力を格納するためにstringstreamを設定します。

[Double is 3.14159] 
関連する問題

 関連する問題