Ubuntu系统c++中获取输出结果
在Ubuntu系统中,可以使用标准输出流(std::cout)来输出结果。以下是一个简单的示例程序:
#include <iostream>
int main() {
int a = 10;
int b = 5;
int result = a + b;
std::cout << "The result is: " << result << std::endl;
return 0;
}
在终端中编译和运行该程序,可以得到输出结果:
The result is: 15
注意,需要在编译时加上 "-std=c++11" 或更高的标志,以支持 C++11 的特性。例如,使用以下命令编译程序:
g++ -std=c++11 program.cpp -o program
然后使用以下命令运行程序:
./program
原文地址: https://www.cveoy.top/t/topic/hIm1 著作权归作者所有。请勿转载和采集!