Reference:
https://en.cppreference.com/w/cpp
https://www.runoob.com/cplusplus/cpp-constants-literals.html
Main() function
#include<iostream>
void main()
{
std::cout << "Is there a bug here?";
}
Error:
||=== Build: Debug in C++practice1 (compiler: GNU GCC Compiler) ===|
\C++practice1\main.cpp|3|error: ‘::main’ must return ‘int’|
C/C++ 11 standard regulate that main() must be int type. Only in this case, operation system will know whether the program runs successfully.
main()必须为int类型并且有返回值,自定义函数可为void类型无返回值。
The correct program should be:
#include<iostream>
int main()
{
std::cout << "Is there a bug here?";
return 0;
}
Console input/output
# include <iostream>
using namespace std;
int ConsoleOutput()
{
cout << "This is a console print and read test:" << endl;
cout << "Pi when approximated is 22/7 = " << 22/7 << endl;
cout << "The actual Pi value is 22/7 = " << 22.0/7 << endl;
cout << "Please input a integer: ";
int InNum;
cin >> InNum;
cout << "The gust entered number " << InNum <<endl;
return 0;
}
int main()
{
cout << "Hello world!" << endl;
return ConsoleOutput();
}
output:
Hello world!
This is a console print and read test:
Pi when approximated is 22/7 = 3
The actual Pi value is 22/7 = 3.14286
Please input a integer: 10
The gust entered number 10