- C ++ file suffix
.cc, .cxx, .cpp, .cp, .c
- Through the command line compiler
1. 编写文件 prog1.cc
int main()
{
return 0;
}
2. 执行命令:
CC prog1.cc
或者:
g++ -o prog1 prog1.cc
3. 运行生成的文件
Linux 系统生成 a.out
Windows 系统生成 prog1.exe
./a.out
4. 获取执行结果
echo $?
- Input / output streams
iostream
istream
: Input stream;cin
: Standard input stream;
ostream
: The output stream;cout
: Standard output stream;cerr
: Printing error information for processing warning, error;clog
: Print General Information;
// 用户输入两个值,计算这两个值的和
#include <iostream>
/*
* sum function:
* Read two numbers and write their sum
*/
int main()
{
// prompt user to enter two numbers
std::cout << "Enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2
<< " is " << v1 + v2 << std::endl;
return 0;
}
References: