掌握基本的输入和输出
1.#include <iostream>
2.输出
2.1 cout +<<
2.2 endl
3.输入
3.1 cin >>
#include <iostream> #include <cstdio> int main() { //1.输出 C++支持C语言的转义字符,目前不需要考虑C++的, //也不需要考虑数据的精度(流控制字符) printf("ILoveyou\n"); std::cout << "ILoveyou\n" ; //没有省略命名空间,std:: using namespace std; cout << "ILoveyou\n"; printf("%d%s\n", 1, "ILoveyou"); //2.C++输出不需要格式控制字符(%d %f %lf) cout << 1 << "ILoveyou" << "\n"; //吃饱了没事干,等效下面写法 cout << 1; cout << "ILoveyou"; cout << "\n"; cout << '\n'; cout << "name" << "\t" <<"age"<< "\n"; char name[20] = "张三"; int age = 11; cout << name << "\t" << age << "\n"; //换行: endl cout << name << "\t" <<age<< std::endl; //2.输入 cout << "input name" << endl; cin >> name; cout << "input age"; cin >> age; cout << name << "\t" << age << endl; cout << "input name,age" << endl; cin >> name >> age; cout << name << "\t"<<age << endl; //3.有些编译器依旧存在字符或者字符串输入跳过问题 char userKey = 0; cin >> userKey; //while (getchar() != '\n'); cout << userKey << endl; char str[20] = ""; cin >> str; cout << str << endl; return 0; }