c++에서 파일을 열어서

ScalDi의 이미지

c++에서 특정 exe을 실행시켜서 특정 위치의 파일을 읽어 드려서 >를 사용해서 다른 파일이나 txt파일로 저장을 할려고 하는데..

FILE *이나 Fopen으로 사용해서 해보아도 안돼서 현재 bat파일로 만들어서 실행하고 있거든요..

exe -옵션 c:\txt.txt > txt.txt 이런 형식...

c언어 안에서 다른 exe파일을 실행 시켜서 특정 위치의 파일을 읽어서 다른 파일로 만들려면 어떠한 방법을 사용해야 돼나요;;

netionics의 이미지

#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
 
int main()
{
	using namespace std;
 
	string filename = "alice.txt";
	string exe = "echo Alice in Wonderland";
	string command = exe + " > " + filename;
	system(command.c_str());
 
	fstream file(filename.c_str());
	string line;
	getline(file, line);
	cout << line << endl;
}

:)