错误 C2297:“<<”:非法,右操作数的类型为“double”

Gop*_*pal 1 c++

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");
Run Code Online (Sandbox Code Playgroud)

我对 C++ 一无所知,只想将 DoubleArray 值打印到日志文件,但它会抛出错误 C2297: '<<' : 非法,右操作数的类型为 'double'

pax*_*blo 5

您需要使用字符串流来做到这一点。包括在内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;
}
Run Code Online (Sandbox Code Playgroud)

这将字符串流设置为包含"Double is 3.14159"并输出括在方括号中的内容:

[Double is 3.14159]
Run Code Online (Sandbox Code Playgroud)