从C++连接MySQL时程序错误中"error: stray ‘302’"编译错误
Compilation error "error: stray ‘302’" in program error while connecting MySQL from C++
我从一个C++示例中获取了sqlconnect:来自C++的SQL连接。我想从C++将数据插入MySQL表。我只是试着运行第一个示例来消除它。请建议我应该处理什么?
#include <stdlib.h>
#include <iostream>
/*
Include the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#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;
cout << "Let's have MySQL count from 10 to 1..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
stmt = con->createStatement();
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test(id INT)");
delete stmt;
/* '?' is the supported placeholder syntax */
pstmt = con->prepareStatement("INSERT INTO test(id) VALUES (?)");
for (int i = 1; i <= 10; i++) {
pstmt->setInt(1, i);
pstmt->executeUpdate();
}
delete pstmt;
/* Select in ascending order */
pstmt = con->prepareStatement("SELECT id FROM test ORDER BY id ASC");
res = pstmt->executeQuery();
/* Fetch in reverse = descending order! */
res->afterLast();
while (res->previous())
cout << "t... MySQL counts: " << res->getInt("id") << endl;
delete res;
delete pstmt;
delete con;
} 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();
cout << ", SQLState: " << e.getSQLState() << »
" )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}
一切都很好。为什么会出现以下编译错误?
temp.cpp:65:3: error: stray ‘302’ in program
temp.cpp:65:3: error: stray ‘273’ in program
temp.cpp:69:3: error: stray ‘302’ in program
temp.cpp:69:3: error: stray ‘273’ in program
我在Stack Overflow上看到了一个类似的问题,但仍然没有得到解决!
第65行和第69行的某个地方有一些奇怪的字符。它们可能是不可见的字符,所以在通常情况下,当您遇到此错误时,只需删除整行,然后再次键入即可。
在这种情况下,这里有一些奇怪的字符:
cout << "(" << __FUNCTION__ << ") on line " »
^^
What's this?
您可能应该删除它,并在下面再删除几行。
哪个"相似线程"?最近出现了一个问题,据描述,该问题是由从一个网站复制粘贴代码引起的,该网站将直引号和短划线翻译成了花引号和长划线。反过来,这些都是使用UTF-8音译的,事实上:
302(八进制)是"--0xC2273是"»"--0xBB
这将产生一个完全有效的UTF8代码"0xC2BB",恰好再次成为字符"»"。现在看看代码中的第65行——它就在那里,正如错误消息所说的那样。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 很多杂散错误 - "error: stray ‘210’ in program in C++"
- C++排序程序中"Stray 1 in program"错误
- 从C++连接MySQL时程序错误中"error: stray ‘302’"编译错误
- 程序中"error: stray '302'"编译错误 代码::块
- 使用 C++11 时出现错误"Error: stray character"