1.1
使用的是visual studio 2017社区版,文件名后缀为.cpp
int main()
{
return 0;
}
1.2
int main()
{
return -1;
}
1.3
#include<iostream>
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
1.4
#include<iostream>
int main()
{
std::cout << "Enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The product of " << v1 << " and " << v2
<< " is " << v1 * v2 << std::endl;
return 0;
}
1.5
#include<iostream>
int main()
{
std::cout << "Enter two numbers:";
std::cout << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of ";
std::cout << v1;
std::cout << " and ";
std::cout << v2;
std::cout << "is ";
std::cout << v1 + v2;
std::cout << std::endl;
return 0;
}
1.6
std::cout << "The sum of " << v1;
<< " and " << v2;
<< " is " << v1 + v2 << std::endl;
不合法,前2行后面有分号,代表语句结束。更改如下
std::cout << "The sum of " << v1;
std::cout << " and " << v2;
std::cout << " is " << v1 + v2 << std::endl;
1.8
std::cout << "/*"; // 合法
std::cout << "*/"; // 合法
std::cout << /* "*/" */; // 不合法
std::cout << /* "*/" /* "/*" */; // 合法
1.9
#include<iostream>
int main