我想找到的時間花在做一定的活動與C總金額來提取數據++和Mac的Automator(你不需要知道 的Automator幫助我)。我正在使用Mac Automator使用「事件摘要」和「新文本文件」操作輸出文本文件。它輸出一個這樣的文本文件: Viewable text file在文本文件中查找單詞使用C++
我目前正在努力尋找一些非常微不足道的東西;我無法在文本文件中準確找到「時間」和「日期」兩個字。如果我找不到「時間」和「日期」這兩個字,我就無法開始處理完成該活動所花費的時間總量或該活動是否在午夜結束(我有時會參加這些活動)。到目前爲止,我認爲我花了四個小時,結果不一。對於任何反饋,我們都表示感謝。
下面的代碼是我目前使用的代碼。我可以在文件的開頭找到「時間」和「日期」這個詞,或者如果「:」在單詞「時間」或「日期」的前面,但是當它位於不同的行上時,程序失敗:
cout << "Reading from the file...." << endl;
infile.open("calendar workflow text.txt");
while(infile.getline(buff, BUFFSIZE, ':')){ //reads everything
cout << buff << endl; // prints everything
if(strcmp("Time",buff)==0){
cout<<"Time found in text\n"<<endl;
}
else if (strcmp("Date",buff)==0){
cout<<"Date found in text\n"<<endl;
}
}
infile.close();
cout<<"Total Time in all events: "<<sumtime<<" hrs"<<endl;
return (0);
如果你想要automator工作流程,我可以給你。
使用'strstr'而不是'strcmp'。後者僅用於精確匹配。 – usr2564301
['std :: string :: find()'](http://en.cppreference.com/w/cpp/string/basic_string/find)是否適合您? –
@Jongware謝謝!我會嘗試的。 –