#include <fstream> #include <iostream> using namespace std; string txtToSql(string infile, string outfile) { cout << infile; ifstream in(infile); ofstream out(outfile); string lineIn, lineOut, sqlresult; //0:数字 1:字符串 if (in) // 有该文件 { int flag = 0, FL[100], length = 0; while (getline(in, lineIn)) // line中不包括每行的换行符 { cout << "line read" << endl; if (flag == 0) { for (int j = 0; j < lineIn.length(); j++) { FL[j] = lineIn[j] - '0'; length++; } lineOut = ""; flag++; continue; } flag++; lineOut = swtichToSql(lineIn, FL, length); if (flag > 2) { lineOut = "," + lineOut; } sqlresult = sqlresult + lineOut; cout << lineIn << endl; cout << lineOut << endl; out << lineOut << endl; // 输入到2.txt中 } } else // 没有该文件 { cout << "no such file" << endl; } cout << sqlresult << endl; return sqlresult; } //对每一行的文本进行处理:字符串加引号,各单元之间加逗号,整行用括号包起来 string swtichToSql(string str, int a[], int len) { string res = "("; const char *p = str.c_str(); for (int i = 0; i < len; i++) { char achar[100] = {'