学习网站:C语言网.
C语言基础:C语言基础.
编译器:Red Panda Dev-C++
1.第一个C++程序
#include2.命名空间// 文件包含;包含iostream标准库; using namespace std; // 声明使用一个叫std命名空间; int main(){ cout << "Hello World." << endl; cout << "Welcome to the C++ world." << endl; return 0; }
// 1.命名空间:解决多个模块间命名冲突的问题; #include3.输入输出using namespace std; int main(){ cout << "Hello C++." << endl; return 0; } // 2.域限定符:: #include int main(){ std::cout << "Hello C++." << std::endl; return 0; } // 3.用using和域限定符一起限定用哪些名字 #include using std::cout; using std::endl; int main(){ cout << "Hello C++." << std::endl; return 0; }
// 1.C++输入输出可以使用printf和scanf函数实现; // 2.C++输入输出流使用cin和cout表示,使用前需要包含标准库iostream; #includeusing namespace std; int main(){ cout << "Hello C++." << endl; // endl起到换行作用; cout << "Welcome to FUXI." << "I am Willard." << endl; return 0; }
// cin输入流:接收一个数据前,先定义一个与之类型一致的变量,用来存放这个数据 // 然后利用cin搭配>>输入操作符,来接收用户从键盘的输入; #includeusing namespace std; int main(){ int numberOne; int numberTwo; cout << "Please input one number:" << endl; cin >> numberOne >> numberTwo; cout << "The value of numberOne is:" << numberOne << endl; cout << "The value of numberTwo is:" << numberTwo << endl; return 0; }



