sqlite3 and C++

Feb 11, 2012 at 3:11pm
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;
}
Feb 11, 2012 at 3:29pm
It's a precedence issue. Put the ternary conditional inside parenthesis
Feb 11, 2012 at 3:44pm
cout << azColName[i] << " = " << ( argv[i] ? argv[i] : )"NULL"<<endl;

you mean this?
still not working or I don't understand what you mean
Feb 11, 2012 at 4:14pm
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
Feb 11, 2012 at 4:30pm
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.
Feb 11, 2012 at 5:59pm
cout << azColName[i] << " = " << (argv[i] ? argv[i] : "NULL") <<endl;
Topic archived. No new replies allowed.