【发布时间】:2017-02-20 22:46:08
【问题描述】:
//all variables are declared in a struct StockPile
//...
string itemid;
string itemdesc;
string datepurchased;
string line;
int unitprice;
int totalsales;
std::string myline;
//...
void displaydailyreport() {
ifstream myfile("stockdatabase.txt");
for(int i=0;std::getline(myfile,myline);i++)
{
// Trying to grep all data with a specific date from a textfile,
cout<<system("grep "<<stockpile[i].datepurchased<<" stockdatabase.txt")<<endl;
}
cout<<endl;
}
当我尝试编译时,它给了我这个错误:
note:template argument deduction/substitution failed:
Main.cpp:853:40: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [6]’
cout<<system("grep "<<stockpile[i].datepurchased<<" stockdatabase.txt")<<endl;
当我尝试使用它运行时,它工作正常:
cout<<system("grep '9oct16' stockdatabase.txt")
stockpile[i].datepurchased 是我可以 cout 存储在我的文本文件中的不同日期的地方,我可以在 for 循环中打印出 stockpile[i].datepurchased 值。
它返回字符串 9oct16 、 10oct16 等,但是当我尝试使用 shell 命令时它不会编译。
【问题讨论】:
-
在
"grep "<<stockpile[i].datepurchased中,编译器无法理解<<的含义。我也不能。
标签: c++ linux shell loops ubuntu