C++学习笔记-摘自c++编程思想

来源:互联网 发布:大数据俱乐部 编辑:程序博客网 时间:2024/05/16 05:38

1. c++中的输出控制。

在c语言中,printf后面跟%d,%o,%x来控制整数的输出,在cPP中通过 cout<<otc<<number; cout<<hex<<number;来表示八进制还是十六进制输出输出。

2. 文件的读写

文件的读写借助于头文件 #include<fstream>来实现,其中,从文件中读用到的是 ifstream,从文件中写用的是ofstream,这两个的应用其实与cin和cout相同,区别是一个的目标为文件,一个目标为控制台。

举例应该:

#include<string>#include<fstream>using namespace std;int main(){    ifstream in("test.txt");//open for reading    ofstram out("target.txt");//open for writing    string s;    while(getline(in,s)    {        out<<s<<"\n";    }}


0 0