我要直接回答这个问题。我通过逐行读取文件,然后合并字符串,但需要一个很好的解释如何使用向量。我的目标是使用系统命令(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 ===|
它在没有添加“| find ...”的情况下工作,但是使用它我可以使用已知的扩展名过滤不需要的文件名。
感谢您的合作,并对二合一问题包抱歉:)
答案 0 :(得分:0)
再次检查#define
...
#define syscomm system("dir /b | find /i /v ".exe .txt")
// String starts here -^ ^
// String ends here ------------------------'
如果它有语法着色,应该在编辑器中非常明显。