I'm trying to make a small program that will create a Batch file, do something in it and then return a string from it, and after it delete the Batch.
I would like to store the output of the batch file in the variable line
.
I tried using getline()
but I think it work with .txt files only. I can be wrong.
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
ofstream batch;
string line;
batch.open("temp.bat", ios::out);
batch <<"@echo OFF\nwmic os get caption /value\nwmic path win32_videocontroller get description /value\npause\nexit";
batch.close();
system("temp.bat");
remove("temp.bat");
};
In my code I simply using system
with my Batch file. I'd like to use cout<<line
.
I expect string called line
would be equal to the output of the Batch file.