PLCXProcess.cpp:4221:76: error: request for member 'c_str' in 'ex.oracle::occi::SQLException::getErrorCode()', which is of non-class type 'int' pLogger->info("Error number:[%s] ;Error Msg:[%s] \n ", ex.getErrorCode().c_str(), ex.getMessage().c_str()); ^
时间: 2024-02-14 19:18:32 浏览: 25
这是一个编译错误,它表示在PLCXProcess.cpp文件的4221行的76个字符处,试图在类型为int的对象上调用c_str()函数。然而,c_str()函数只适用于string类型的对象。
推测这里的ex.getErrorCode()返回的是int类型的错误码,而不是string类型。因此,可以尝试将错误码转换为string类型,然后再调用c_str()函数。可以使用to_string()函数将整数转换为字符串,例如:
```
pLogger->info("Error number:[%s] ;Error Msg:[%s] \n ", to_string(ex.getErrorCode()).c_str(), ex.getMessage().c_str());
```
相关问题
PLCXProcess.cpp: In member function 'int CPLCXProcess::INSERTCXDATA(oracle::occi::Connection*, std::vector<PCXPackage>, long int&, std::string)': PLCXProcess.cpp:1042:30: error: no matching function for call to 'CPLCXProcess::GetCurLocalDate(std::string&)' GetCurLocalDate(strLocalDate); ^ PLCXProcess.cpp:1042:30: note: candidate is: In file included from PLCXProcess.cpp:9:0:
这是一个编译错误,错误信息显示在调用 `GetCurLocalDate` 函数时传递了一个错误的参数类型。
在C++中,参数类型非常重要。函数的参数类型必须与函数声明中的参数类型完全匹配。在这种情况下,`GetCurLocalDate` 函数声明的参数类型是 `char*`,而实际传递的参数类型是 `std::string`,它们不匹配。
解决方法:
有两种解决方法:
1. 将 `GetCurLocalDate` 函数的参数类型改为 `std::string`,例如:
```
void GetCurLocalDate(std::string& szLocalDate);
```
然后在函数实现中,将日期字符串赋值给 `szLocalDate`。这样就可以使用 `std::string` 类型的参数调用函数了。
2. 将 `std::string` 转换为 `char*` 类型,例如:
```
std::string strLocalDate = "2022-01-01";
char* szLocalDate = new char[strLocalDate.size() + 1];
std::strcpy(szLocalDate, strLocalDate.c_str());
GetCurLocalDate(szLocalDate);
delete[] szLocalDate;
```
在这种情况下,我们先创建一个指向字符数组的指针 `szLocalDate`,然后使用 `strcpy` 函数将 `std::string` 类型的字符串复制到字符数组中。最后,我们将指向字符数组的指针作为参数传递给 `GetCurLocalDate` 函数。注意,在使用完字符数组后,需要使用 `delete` 关键字释放内存,以免造成内存泄漏。
PLCXProcess.cpp:3721:51: error: expected ')' before ';' token pStmt->setDouble(4, atof(strTradeAmount.c_str()); ^ PLCXProcess.cpp:3722:46: error: expected ')' before ';' token pStmt->setDouble(5, atof(strAgtFee.c_str()); ^ PLCXProcess.cpp: In member function 'int CPLCXProcess::insertcsdaily(oracle::occi::Connection*, XHX_PLCX_REPACKBODY*, bool, bool)': PLCXProcess.cpp:3893:51: error: expected ')' before ';' token pStmt->setDouble(4, atof(strTradeAmount.c_str()); ^ PLCXProcess.cpp:3894:46: error: expected ')' before ';' token pStmt->setDouble(5, atof(strAgtFee.c_str()); ^
这是一个编译错误,看起来是在PLCXProcess.cpp文件中的insertcsdaily函数中的setDouble方法中出现了语法错误。缺少一个右括号')',可能是因为atof函数的调用缺少右括号。你可以检查一下PLCXProcess.cpp文件中这些行的代码,看看是否有语法错误,并且确保所有函数调用都有正确的参数列表。