C++ fstream错误:与';不匹配;操作员<<';在';wrf<<&引用;在“'|
因此,我正在尝试编写一个程序,将生成SQL insert到命令语句中,并将它们写入C++ fstream错误:与';不匹配;操作员<<';在';wrf<<&引用;在“'|,c++,fstream,C++,Fstream,因此,我正在尝试编写一个程序,将生成SQL insert到命令语句中,并将它们写入.txt文件。对于start,我只编写了一些代码,这些代码只会在命令中写入insert的开始部分:表名和列名 #include <iostream> #include <iomanip> #include <stack> #include <queue> #include <fstream>' using namespace std; ifstream
.txt
文件。对于start,我只编写了一些代码,这些代码只会在命令中写入insert的开始部分:表名和列名
#include <iostream>
#include <iomanip>
#include <stack>
#include <queue>
#include <fstream>'
using namespace std;
ifstream wrf;
int main()
{
queue<string>row1;
queue<string>row2;
queue<string>values;
// queue<void>storeValues;
string table;
int columnVal;
int valuesVal;
string insertQ = "insert into";
string valQ = "values";
string columnName;
cout << "Insert table name: ";
cin >> table;
cout << "Number of columns: ";
cin >> columnVal;
int temp = columnVal;
cout <<"------------------------------\nStulpeliai:\n";
//------------------------------
while(temp)
{
cin >> columnName;
row1.push(columnName);
temp--;
}
//int temp2 = valuesVal;
wrf.open ("DB.txt");
cout << "\n------------------------------\nTEST\n";
cout << insertQ << table << "\n\t(";
wrf >> insertQ >> table >> "\n\t(";
while(row1.size() != 1)
{
cout << row1.front() << ", ";
wrf >> row1.front() >> ", ";
row2.push(row1.front());
row1.pop();
}
cout << row1.front() <<") ";
wrf >> row1.front() <<") ";
row2.push(row1.front());
row1.pop();
wrf.close();
return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
ifstream-wrf;
int main()
{
第1行;
第2行;
排队值;
//队列存储值;
字符串表;
int-columnVal;
int valuesVal;
string insertQ=“插入”;
字符串valQ=“值”;
字符串列名;
cout>表格;
cout>columnVal;
int-temp=columnVal;
cout列名称;
行1.push(列名称);
温度--;
}
//int temp2=值瓦尔;
wrf.open(“DB.txt”);
cout table>>“\n\t(”;
while(row1.size()!=1)
{
cout row 1.front()>>“,”;
第2行。推(第1行。前());
行1.pop();
}
coutwrf是输入流的ifstream
。
您只能在上使用operator>
,operator如果要写入wfs
,您的代码应修改为:
ofstream wrf;
// in the definition
// .....
//...
// when outputting to the file
wrf << insertQ << table << "\n\t(";
while(row1.size() != 1)
{
cout << row1.front() << ", ";
wrf << row1.front() << ", ";
row2.push(row1.front());
row1.pop();
}
cout << row1.front() <<") ";
wrf << row1.front() <<") ";
row2.push(row1.front());
row1.pop();
wrf.close();
return 0;
}
流wrf的;
//在定义中
// .....
//...
//输出到文件时
wrf问题是所有运算符都不起作用。我尝试了和>,但非运算符和>都起作用,同样的错误,那么问题的根源在哪里?\n您试图用wrf>>insertQ>>table>>做什么?\n\t(;
?我正在尝试向文件中添加字符串“insert-into”和一个表的名称。所以wrf
需要是一个,所以使用操作符,请阅读我给你的ofstream链接,它比我更好地解释它是什么。