首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用mojibake编译的C++程序?

用mojibake编译的C++程序?
EN

Stack Overflow用户
提问于 2012-03-07 03:58:18
回答 1查看 224关注 0票数 2
代码语言:javascript
复制
#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++的第二天,所以请原谅我糟糕的格式化编码和其他nooby错误。这总是在我得到一个未处理的异常之前出现。

EN

回答 1

Stack Overflow用户

发布于 2012-03-07 04:39:17

我相信您使用的API会返回std::string对象。

在这种情况下,您可能希望在代码顶部添加一个字符串,以便为std::#include <sstream>类定义好一个'<<‘运算符。

我不确定这个解决方案,因为我希望你得到一个编译错误,以某种方式暗示没有运算符'<<‘找不到。

试着把它放在你的代码中,然后立即从main()调用它,看看流运算符是否正常工作。注意,它将使您的程序退出。

代码语言:javascript
复制
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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9590913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档