我正在直接回答這個問題。我通過逐行讀取文件併合並字符串來完成,但需要一個很好的解釋來說明如何使用矢量來完成。我的目標是使用系統命令(Windows XP,7)來檢查目錄內容,並將它們直接發送到'vector sysoutp'作爲示例,然後將其與第二個文件中的信息合併到新文件中。有任何想法嗎?如何在另一個或文件中使用矢量合併兩個或多個流?
只是爲了我的代碼示例部分:
while (getline(myinputfile, line))
{
lines++;
found = line.find(countchars);
if (found!=string::npos)
{
line.erase(int(found) + 4);
myoutputfile << line << endl;
}
}
其中myinputfile充滿了「syscomm」,這個想法是用向量轉換但顯然,當我試圖做類似getline(cin, tmp)
其中「CIN」是syscomm沒有任何反應(當然,錯誤彈出):(
我也有和使用該preproccessor指令
#define syscomm system("dir /b | find /i /v ".exe .txt")
時出現錯誤:
createlist.cpp|15|warning: missing terminating " character [enabled by default]|
createlist.cpp|53|error: missing terminating " character|
createlist.cpp||In function 'int main()':|
createlist.cpp|53|error: request for member 'exe' in '"dir /b | find /i /v "', which is of non-class type 'const char [21]'|
||=== Build finished: 2 errors, 1 warnings ===|
它沒有添加「|」找到......」,但使用它,我可以過濾不需要的文件名與他們已知擴展。
謝謝合作和遺憾,2合1的問題包:)
一個問題,請。 – 2012-02-08 11:19:38
那麼,什麼是讀一行在命令輸出線的基本算法,並在它們插入以下是這個向量rt行動?我知道怎麼做,但閱讀很難理解... Did: 'while(!inputcomm.eof()) { sortedvector.push_back(inputcomm.getline(buffer,10)); } sort(sortedvector.begin(),sortedvector.end()); pclose(inputcomm); return sortedvector;' 其中inputcomm爲例如'FILE * inputcomm = popen(「dir/b | findstr/i \」\\ <*。sd \「」,「rt」);' :( – 1000Gbps 2012-02-12 08:45:04