繁体   English   中英

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

[英]error C2297: '<<' : illegal, right operand has type 'double'

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");

我不知道有关c ++的任何信息,只是想将aDoubleArray值打印到日志文件中,但是会引发错误C2297:'<<':非法,右操作数的类型为'double'

您需要使用字符串流来执行此操作。 包括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"并输出包含在方括号中的输出:

[Double is 3.14159]

您正在将“ aDoubleArray value at 0 -------->”视为流。 常量字符串不是输入流。 请访问http://www.fredosaurus.com/notes-cpp/strings/stringstream.html,因为stringstreams可能就是您想要的。

您将必须执行以下操作:

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");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM