- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
#include "StdAfx.h"
#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
using namespace std;
int main(void){
cout << endl;
try{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
driver = get_driver_instance();
con = driver->connect("REMOVED", "REMOVED", "REMOVED");
con->setSchema("REMOVED");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT username FROM player WHERE id=1");
cout << "Username: " << res->getString("username") << endl;
delete res;
delete con;
cout << "Done.";
system("pause");
}catch(sql::SQLException &e){
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode() << endl;
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
system("pause");
}
return 0;
}
变成... http://i.imgur.com/cIVnl.png
这是怎么回事? :( 这只是我使用 C++ 的第二天,所以请原谅我糟糕的格式化编码和其他笨拙的错误。这总是在我遇到未处理的异常之前出现。
最佳答案
我相信您正在使用的 API 会返回 std::string 对象。
在这种情况下,您可能想要添加一个 #include <sstream>
到代码的顶部,以便为 std::string 类定义一个“<<”运算符。
我不确定这个解决方案,因为我希望你会得到一个编译错误,以某种方式暗示找不到运算符“<<”。
尝试将其粘贴到您的代码中并立即从 main() 中调用它,以查看流操作符是否正常工作。请注意,这将使您的程序退出。
void SimpleStrings()
{
std::string str("String in a std::string");
const char *psz = "const-char-str";
std::cout << "std::string: " << str << std::endl << "const char *: " << psz << std::endl;
exit(1);
}
关于c++ - 编译的 C++ 程序充满了 mojibake?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9590913/
我希望这不是一个太具体的问题...任何想法都值得赞赏。 当有人填写我的联系表单(UTF-8 编码)时,数据会正确进入 MySQL 数据库(全程 UTF-8 编码),并且回复电子邮件会发送给填写表单的人
使用 react-native v0.31.0在 iOS (目前在 iOS9 和 iOS10 上)。 我在 中有一个非拉丁文本Component有时我会这样看: 但它实际上应该是这样的: 我的绕行是
#include "StdAfx.h" #include #include #include "mysql_connection.h" #include #include #include
在《辛普森一家》第 12 季第 7 集“The Great Money Caper”中,几年前我注意到俄罗斯飞船上的“胡言乱语”标志。今天随机,我决定搜索看看是否有人解码了它们但找不到任何结果。 我怀
Mojibake问题 [我使用netbeans - jsf 2.2 - primefaces 4.0 - Mysql数据库] 我在 JSF 应用程序中使用阿拉伯语,不幸的是,阿拉伯语值作为其他字符发送
我有一个用 Perl 和 MySQL 编写的基于 Web 的项目。我们使用模板工具包来呈现 HTML 页面。我们在 DBI 类上编写了一个自定义包装器来与 MySQL 交互。 由于这是一个遗留项目,我
我有以下 index.jsp: 和属性文件 messages_ru_RU.properties: login = Логин 问题是我在输出中得到了
我正在使用 mutagen 读取 mojibaked ID3 标签。我的目标是在学习编码和 Python 对其处理的同时修复 mojibake。 我正在处理的文件有一个 ID3v2 标签,我正在查看它
我想使用 HTTPServletResponse 从 servlet 向客户端发送阿拉伯语数据 我正在尝试这个 response.setCharacterEncoding("UTF-8"); resp
我是一名优秀的程序员,十分优秀!