共分为三种:
1.iostream
普通的输入与输出,包括cin,cout,cerr,clog
cin:从键盘输入 :cin >>
cout:输出到屏幕 :cout <<
cerr:主要就是不会进入缓冲区,会直接打印内容
2.sstream
字符串的输入与输出,包括ostringstream,istringstream两种
istringstream:从字符串输入到内存中
ostringstream:输出到字符串中
3.fstream
文件的输入与输出,包括ifstream,ofstream两种
ifstream:从文件中输入到内存
ofstream:输出到文件中
文件的写入还可以使用二进制的方式写入:ifstream::binary
总结:这里的输入与输出与标准的输入输出的区别就是看你到底是输出到哪里,或者从哪里输入的区别,对于文件与字符串的IO流的话,有好多的函数可以使用,文件中的getline,close等,字符串中的str函数等等都是我们在进行这些操作的时候经常会使用的函数,也是相当的方便
下面是我的一个小小的测试
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
void filetest()
{
/*ofstream ofs("1.txt");
ofs << "hello, world" << endl;
ofs.close();*/
ifstream ifs("1.txt");
char s[20];
ifs.getline(s, 19);
cout << s;
ifs.close();
}
void stringtest()
{
ostringstream oss;
oss << "hello ,world!";
cout << oss.str() << endl;
}
int main()
{
filetest();
stringtest();
cerr << "error";
return 0;
}