-4

I am using C++, Unicode. What I am trying to do is pretty much this:

int Main(){

int test = 5;
std::cout << "hi " << test;
return 0;
}

Output: hi 5

I am using C++ so which method should I use? So I can add a int/NullTerminated. The reason for this is so I can grab input from the user in a Textbox and then send a query to SQL. I am not using a CMD line, I making a GUI interface with win32, so that's why I use wchar_t and not wstring.

  • 1. It's `int main()` (C++ is case sensitive). 2. With that typo fixed, your program will produce the desired output, so what is your question? 3. You aren't using wchar_t. 4. I don't understand why you can't use wstring with win32. – Martin Bonner supports Monica Dec 20 '15 at 20:32
  • Sorry I didn't type that into my IDE, I just typed it out in the forum. I use wchar_t for normal windows programming with GetWindowText() etc. What I want to do is have a normal string like "INSERT INTO ExampleTable(UserName) VALUES(TheVariable)) Also I have found out how to use wstring with functions like GetWindowText so I probably will change to it. – Trevin Corkery Dec 20 '15 at 20:41
  • So, what is your question? – Martin Bonner supports Monica Dec 20 '15 at 20:47
  • (std::wstring("hi ") + std::to_wstring(test)).c_str() – Jonathan Potter Dec 20 '15 at 20:55

1 Answers1

0

I did it like this:

case SQL_SUCCESS_WITH_INFO: {
                    SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &hSTMT);
                    SQLSMALLINT test[1];
                    SQLBindCol(hSTMT, 7, SQL_SMALLINT, test, sizeof(test), NULL);

                    std::wstringstream SQLStringStatementStream;
                    std::wstring SQLStringStatement, SQLStringStatement2;
                    GetWindowText(hUserID, &SQLStringStatement2[0], 18);

                    SQLStringStatementStream << L"INSERT INTO Table(test) VALUES( " << &SQLStringStatement2[0] << " );";    
                    SQLStringStatement = SQLStringStatementStream.str();

                    SQLExecDirect(hSTMT, &SQLStringStatement[0], SQL_NTS);
                    SQLGetDiagRec(SQL_HANDLE_STMT, hSTMT, 1, SQLState, &SQLInt, sqlErrorMessage, sizeof(sqlErrorMessage), &SQLErrorSize);
                    break;
                    }
                }