다음 코드를 가지고 있지만이를 실행할 때 출력이 텍스트 파일에 복사되는 대신 인쇄됩니다.인쇄 시스템 명령을 텍스트 파일로 변환 C++
void checkText()
{
ifstream my_file("test.txt");
if (my_file.good()) {
cout << "File exist" ;
}
else {
ofstream outputFile;
outputFile.open("test.txt");
outputFile << system("head -n 1024 words.txt");
outputFile.close();
cout << "Done!\n";
}
}
어떻게 시스템 명령을 텍스트 파일로 인쇄합니까?
가능한 복제 [명령을 실행하고 POSIX를 사용하여 C++ 내에서 명령의 출력을 얻을하는 방법?] (http://stackoverflow.com/questions/478898/how-to-execute-a-command- c-using-posix 내 명령어 출력 결과 출력) – Logman