Console system()输出为int变量

时间:2013-09-13 14:51:24

标签: c++ xcode console int system

我正在尝试使用以下system()函数读取屏幕的分辨率。

system("system_profiler SPDisplaysDataType | grep Resolution | uniq | awk '{print $2}' |  cut -d 'x' -f2");

不幸的是我不能使用popen我正在使用Xcode并且程序与popen崩溃,所以它必须是system()。但是,问题是我不知道如何收集系统调用发送到控制台的数据到int变量。我试过了;

w << std::cerr << std::endl;
const std::string W(w.str());
int j = atoi(W.c_str());
cerr << "VALUE 2: " << j;

这是为了将系统提供的cerr出口转换为字符串,然后是char,最后是int :)但是不起作用。 任何的想法?提前谢谢。

0 个答案:

没有答案