【发布时间】:2017-01-24 22:04:19
【问题描述】:
有没有一种简单的方法可以将系统命令的输出转换为 C++ 中的字符串?
这是我的意思的例子,试图将时代变成一个字符串。 这当然行不通。
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
int main(){
string t = system("date +%s");
cout << "Time " << t << endl;
return 0;
}
【问题讨论】:
-
你的平台是什么?
-
为什么不直接使用
strftime和time? -
syetem()返回什么? -
系统返回一个整数,0表示成功,-1表示失败。它不是系统命令的输出。
标签: c++