sqlite3 and C++

heres the part of code i am writing for using sqlite3 and its an error i can't comprehend


 invalid operands of types 'const char [5]' and '<unresolved overloaded function type>' to binary 'operator<<'


1
2
3
4
5
6
7
8
9
10
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
    int i;
    for(i=0; i<argc; i++)
    {
      cout << azColName[i] << " = " <<  argv[i] ? argv[i] : "NULL"<<endl;
    }
    cout << endl;
    return 0;
}
It's a precedence issue. Put the ternary conditional inside parenthesis
cout << azColName[i] << " = " << ( argv[i] ? argv[i] : )"NULL"<<endl;

you mean this?
still not working or I don't understand what you mean
Actually I am trying to convert this C code into C++

printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");

can't seem to be doing it right
I guess I would do that like this:
1
2
3
4
5
6
7
8
9
10
11
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
    int i;
    for(i=0; i<argc; i++)
    {
      std::string argString = argv[i] ? argv[i] : "NULL";
      cout << azColName[i] << " = " <<  argString <<endl;
    }
    cout << endl;
    return 0;
}


the compiler may not be seeing that if statement as bindible output class. Where what I did makes it one.
cout << azColName[i] << " = " << (argv[i] ? argv[i] : "NULL") <<endl;
Topic archived. No new replies allowed.