//以前学习过C语言,这是学习C++的笔记.所有的代码在dev c++ 5.15 下测试
/*
在C++ 中,仍可以用printf,scanf输入输出语句,只需include <cstdio>
但C++ 提供了 iostream 库,提供了更方便的输入输出方法,以流的方式处理各种
数据的输入输出。
*/
#include <iostream>
using std::cin; //代表标准输入设备,一般是键盘
using std::cout; // 代表标准输出设备,一般是屏幕
using std::cerr; // 代表标准错误输出设备,一般是屏幕
using std::endl; // 强制输出并换行
void Foo() {
int a = 5;
double b = 5.55;
cout << "Hello World!" << endl ;
cout << " a=" << a << ",b=" << b << endl;
}
int main(int argc, char **argv) {
char input = 0;
cout << "Hello! This is a console application." << endl;
cout << "Press q to quit, press a to execute foo." << endl;
while (1) {
cin >> input; //读入一个字符到变量 input中
if (input == 'a') {
Foo();
} else if (input == 'q') {
break;
} else if (input != '\n') {
cout << "Unknown command '" << input << "'! Ignoring...\n";
}
}
return 0;
}
学点C++ 笔记2:输入输出流
最新推荐文章于 2024-02-13 23:35:08 发布