前言:
个人学习纪录用,不保证正确率和准确性。
练习:
1.1 查阅你使用的编译器的文档,确定它所使用的文件命名约定,编译并运行main程序。
编译器:VS2013。
int main()
{
return 0;
}
1.2 改写程序,让它返回-1,返回-1通常被当作程序错误的标识。重新编译运行你的程序,观察你的系统如何处理main返回的错误标识。
int main()
{
return -1;
}
1.3 编写程序,在标准输出上打印Hello,World。
#include<iostream>
int main()
{
std::cout << "Hello,World" << std::endl;
return 0;
}
1.4 我们的程序使用加法运算符+来将两个数相加。编写程序使用乘法运算符*,来打印两个数的积。
#include<iostream>
int main()
{
//声明2个int型变量
int a = 0;
int b = 0;
std::cin >> a >> b;
std::cout << "打印两个数的乘积:" << a*b << std::endl;
return 0;
}
1.5 我们将所有输出操作放在一条很长的语句中。重写程序将每个打印操作放在独立的语句中。
#include<iostream>
int main()
{
//声明2个int型变量
int a = 0;
int b = 0;
std::cin >> a;
std::cin >> b;
std::cout << "打";
std::cout << "印";
std::cout << "两";
std::cout << "个数的乘积:";
std::cout << a*b;
std::cout<< std::endl;//换行作用
return 0;
}
=====================================================================剩余练习答案请参考我的github。
https://github.com/deadwin/MyCppExerciseAnswer