for循环批处理数据并将其抛出到c ++ part2中的MySQL查询

时间:2014-10-03 07:41:22

标签: c++ mysql

    void write_token_to_data()
    {

        int count=0;
        string str;
        typedef double* DynamicMatrix[l+m];
        // DynamicMatrix Count;
        typedef double* DynamicMatrix2[l+m];
        //DynamicMatrix2 Prob;
        for(int i=0; i<(l+m); i++)
        {
            for(int j=0; j<(l+m); j++)
            {
                //--------------------------------------------------
                if (count >100 || count == 0)
                {
                    // execute the string
                    //mysqlinsert(str);
                    // initialize str as empty string
                    str = "INSERT INTO EM ( sourceindex,targetindex,source,target) VALUES";
                    count = 0;
                }
                if (count <= 100)
                {
                    // concatinate the string with prev str
                    str +=(i,j,combine[i],combine[j])+',';
                    cout<<str<<endl;
                    count++;
                }

            }
        }
        //outfile.close();
    }//end of function

问题是关于str转到sql查询 我发现我的代码是str 并且str消除'(',')'和i和j i和j应该是索引号,类型是整数 如何在没有错误的情况下更改此代码

1 个答案:

答案 0 :(得分:1)

try like this !!!! Not tested
str += '('+ i +',' + j +',' + combine[i] + ',' + combine[j] ')'+',';