//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;
}
當我嘗試編譯它給了我這個錯誤:錯誤時使用C運行shell命令++ Ubuntu Linux操作系統
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'中,編譯器找不到'<<'的意思。我也不能。 – v7d8dpo4