【问题标题】:Convert MySQL result to int (C++)将 MySQL 结果转换为 int (C++)
【发布时间】:2023-03-19 17:32:01
【问题描述】:

我正在使用变量 row[2] 从 MySQL 检索结果。 该变量的数据在 mysql 表中是 int 但我无法将其放入 c++ 中的 int 变量中,因为我收到错误消息

average.cpp:40: error: invalid conversion from char* to int

第 40 行是total += row[2];

我做错了什么:?

谢谢

【问题讨论】:

  • 我多一点上下文会有所帮助。

标签: mysql c int average


【解决方案1】:

看看错误,当你得到它的值时它被转换为一个char *,所以你必须把它转换回int。

#include <sstream>
#include <string>
using namespace std;

string input(row[2]);
stringstream SS(input);
int n;

SS >> n;

total+=n;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多