gpt4 book ai didi

c++ - fstream 错误 : no match for 'operator<<' in 'wrf << "insert into"'|

转载 作者:搜寻专家 更新时间:2023-10-31 00:59:49 26 4
gpt4 key购买 nike

因此,我正在尝试编写一个程序来生成 SQL 插入命令语句并将它们写入 .txt 文件。对于开始,我只写了一些代码,这些代码只会写一个插入命令的开始:表名和列名。

#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;
}

出于测试原因,我尝试编写 ifstream 语句来测试它如何将其写入 .txt 文件,但我遇到了不匹配错误...

有什么想法吗?

附言我只是出于学习原因使用队列。我希望问题足够全局化。

最佳答案

如果你想写入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;
}

关于c++ - fstream 错误 : no match for 'operator<<' in 'wrf << "insert into"'|,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32627721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com