2017-04-10 84 views
0
while(in) { 
memset(str, 0,1024); 
in.getline(str, 1024); // delim defaults to '\n' 
string output = modifyString(str); 
if (output != ""){ 
    cout << output << endl; 
    string output1 = "INSERT INTO DATA_SRC "\ 
    "VALUES (" + output + ");"; 
    cout << output1 << endl; 
    const char * command = output1.c_str(); 
    cout << output << endl; 
    rc = sqlite3_exec(db, command, callback, 0, &zErrMsg); 
    if(rc != SQLITE_OK){ 
    fprintf(stderr, "SQL error: %s\n", zErrMsg); 
    sqlite3_free(zErrMsg); 
    return 1; 
    } 
} 

對於這裏,我+兩個字符串在一起。 並且輸出的內容是: 'D3318','D.A。 Kline','通過TLC衍生物的GLC分離定量測定水果中的糖',1970,'AOAC International Journal',53,6,1198,1202我組合了C++中的兩個字符串,但出錯了

這是好的。但是在我將它與其他人結合後。

預計: INSERT INTO DATA_SRC值('D3318','DA Kline','定量測定水果中糖類物質的TLC衍生物的GLC分離',1970年,'AOAC國際雜誌',53,6,1198 ,1202); ('D3318','DA Kline','通過GMS分離TMS衍生物定量測定水果中的糖',1970,'Journal of AOAC In';國際',53, 6,1198,1202

我現在不是爲什麼。

+0

歡迎來到Stack Overflow!請** [編輯] **您的問題與[mcve]或[SSCCE(短,自包含,正確示例)](http://sscce.org) – NathanOliver

+1

我不知道爲什麼要麼,可能是因爲問題是在'modifyString'中,你不顯示? – crashmstr

+0

您是否嘗試用調試程序逐句通過您的代碼? – pm100

回答

1

您的modifyString函數(您沒有顯示)正在將空字節複製到字符串的末尾。字符串輸出函數將在空字節上停止,以便與C字符串兼容。

相關問題