小编boo*_*oka的帖子

C++ Concating字符串导致"类型'const char*'和'const char"的无效操作数

我想连接两个字符串,但我得到错误,我不明白如何克服此错误.

有没有办法将此const char*转换为char?我应该使用一些解除引用吗?

../src/main.cpp:38: error: invalid operands of types ‘const char*’ and ‘const char [2]’ to binary ‘operator+’
make: *** [src/main.o] Error 1
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试以这种方式组成"底部"字符串,它的工作原理:

bottom += "| ";
bottom += tmp[j];
bottom += " ";
Run Code Online (Sandbox Code Playgroud)

这是代码.

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iterator>
#include <sstream>

int main(int argc, char* argv[]) {

    ifstream file("file.txt");

    vector<string> mapa;
    string line, top, bottom;

    while(getline(file,line)){
        mapa.push_back(line);
    }

    string tmp;
    for(int i = 0; i < mapa.size(); i++)
    {
        tmp = mapa[i];
        for(int …
Run Code Online (Sandbox Code Playgroud)

c++ concat char

6
推荐指数
2
解决办法
1万
查看次数

C++从sqlite3回调函数填充向量?

我有一个像这样的sqlite3表"地址":

+----+------+--------+
| ID | name | number |
+----+------+--------+
| 1  | John | 413434 |
+----+------+--------+
Run Code Online (Sandbox Code Playgroud)

我想填充全局矢量,我可以在其他地方使用它并将其与其他一些数据连接起来.到目前为止,我有这个:

...
#include <sqlite3.h>

using namespace std;

static int callbackDB(void *NotUsed, int argc, char **argv, char **szColName)
{
    for(int i = 0; i < argc; i++)
        cout << szColName[i] << " = " << argv[i] << endl;

    return 0;
}

int main(int argc, char* argv[]) {
    vector<vector<string> > table;
    for( int i = 0; i < 2; i++ )
        table.push_back(std::vector< std::string >()); …
Run Code Online (Sandbox Code Playgroud)

c++ sqlite

2
推荐指数
1
解决办法
3832
查看次数

标签 统计

c++ ×2

char ×1

concat ×1

sqlite ×1