c++ 快速入门
[html]
#include <iostream>
int main()
{
std::cout << "Enter two numbers:" << std::endl;
int v1,v2;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1 + v2 << std::endl;
return 0;
}
输出:
[html]
pateo@pateo-B86N53X:~/work/study$ g++ -o main main.cc
pateo@pateo-B86N53X:~/work/study$ ls
main main.cc
pateo@pateo-B86N53X:~/work/study$ ./main
Enter two numbers:
1
2
The sum of 1 and 2 is 3
pateo@pateo-B86N53X:~/work/study$
[html]
pateo@pateo-B86N53X:~/work/study$ ./main
Enter two numbers:
4 6
The sum of 4 and 6 is 10
pateo@pateo-B86N53X:~/work/study$
endl 说明:操作符,将它写入输出流时,具有输出换行的效果,并刷新与设备相关联的缓冲区,通过刷新缓冲区,用户可立即看到写入到流中的输出
其他说明:c++ 也有前++和后++,相应的for循环等基础语法是一样的
[html]
#include <iostream>
int main()
{
int sum = 0, value;
while(std::cin >> value)
sum += value;
std::cout << "Sum is " << sum << std::endl;
return 0;
}
停止动作:两次ctr+d
输出:
[html] www.zzzyk.com
pateo@pateo-B86N53X:~/work/study$ ./main
1 2 3 Sum is 6
pateo@pateo-B86N53X:~/work/study$
补充:软件开发 , C++ ,