摘要: //第二十二章 6未命名的命名空间/*#include <iostream>using namespace std;namespace { int x=2;}namespace { int y=3;}int main(){ cout<<"x:"<<x<<" y:"<<y<<endl; //输出的结果就是未命名空间的x和y的值,其实我们也可以把它们看帮是全局的变量 return 0;}*/// 1 未命名命名空间与全局变量的区别// 2 未命名命名空间与static的区别// 3 未命 阅读全文
posted @ 2012-10-01 23:51 简单--生活 阅读(469) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 4使用关键字using//不地using namespace只有在它声明的作用域中有效,假如超出这个作用域,那么就要重新声明才能够直接使用该空间中的成员/*#include <iostream>using namespace std;namespace num{ int x=10; int y=20;}int main(){ { using namespace num; cout<<"x:"<<x<<" y:"<<y<<endl; } //cout<<&q 阅读全文
posted @ 2012-10-01 23:50 简单--生活 阅读(169) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 5为你的命名空间取个别名/*#include <iostream>using namespace std;namespace people_compay_boss{ int x=9;}namespace pcd = people_compay_boss;int main(){ cout<<pcd::x<<endl; cout<<people_compay_boss::x<<endl; return 0;}*/ 阅读全文
posted @ 2012-10-01 23:50 简单--生活 阅读(187) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 1什么是命名空间//命名宽间主要解决命名冲突的问题,即重名问题/*#include <iostream>using namespace std;int x=1; namespace people{ char name[10] = "Jack";};int main(){ int x=3; cout<<"x:"<<x<<endl; //这个是局部的x变量 cout<<"::x:"<<::x<<endl; //全局的x变量, 前面添加作用域 阅读全文
posted @ 2012-10-01 23:49 简单--生活 阅读(186) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 2创建命名空间//1 扩充命名空间的内容// 同一个命名空间可以在程序中出现多次,也就是说我们可以多次重复创建同一个命名空间//2 尽量在命名空间之外定义函数/*#include <iostream>using namespace std;namespace func{ void swap(int &rx, int &ry); void compare(int x, int y);}int main(){ int x=5, y=6; func::swap(x,y); func::compare(x,y); return 0;}void func::s 阅读全文
posted @ 2012-10-01 23:49 简单--生活 阅读(181) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 3使用命名空间/*#include <iostream>using namespace std;namespace func{ const int cx=20; const int cy=50; class num{ public: num(); ~num(); void size(int a, int b); void swap(int rx, int ry); void compare(int ax, int ay); int returnX(); int returnY(); static int z; private: int x; int y;... 阅读全文
posted @ 2012-10-01 23:49 简单--生活 阅读(164) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 15sstream字符串输入输出流类/*#include <iostream>#include <sstream>#include <string>using namespace std;int main(){ ostringstream out; //ostringstream 类从ostream类派生而来,因此ostringstream类对像有cout对像的特征 char *str = "hello world"; float num=314.57f; out.precision(2); out<<fix 阅读全文
posted @ 2012-10-01 14:03 简单--生活 阅读(169) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 11指定读取文件中的数据seekg()//假如我们不想全部读入文件中的数据,而是只读取其中的某项数据,那么fstream类的seekg()成员函数可以为我们达到目的/*#include <iostream>#include <fstream>using namespace std;int main(){ ofstream fout("people.txt"); if(!fout){ cout<<"创建文件失败"; } fout<<"1234567890asfdsfasfasfas 阅读全文
posted @ 2012-10-01 14:02 简单--生活 阅读(1691) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 12输出数据到文件指定位置处seekp()//想要在文件指定位置处输出数据,那么fstream类的seekp()成员函数可以为我们达到目的/*#include <iostream>#include <fstream>using namespace std;int main(){ ofstream fout("people.txt"); if(!fout){ cout<<"创建文件失败"<<endl; } fout<<"ABCDEFGLIJKLMIOPQ"; 阅读全文
posted @ 2012-10-01 14:02 简单--生活 阅读(321) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 13seekp()和seekg()函数的结合使用/*#include <iostream>#include <fstream>#include <iomanip>using namespace std;const int num = 10;struct people{ char name[num]; int age; float pay;};const char*file = "people13.txt";void deleteline(){ while(cin.get() !='\n') continu 阅读全文
posted @ 2012-10-01 14:02 简单--生活 阅读(795) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 14临时文件/*#include <cstdio>#include <iostream>using namespace std;int main(){ cout<<"tmpnam()函数的最多调用次数:"<<TMP_MAX<<"\n 临时文件名的字符数目:"<<L_tmpnam<<"字符"<<endl; char pszName[L_tmpnam]={'\0'}; cout<<"下面是 阅读全文
posted @ 2012-10-01 14:02 简单--生活 阅读(152) 评论(0) 推荐(0) 编辑
摘要: // 第二十一章流 8打开多个文件// 1 同时打开多个文件// 2 依次打开多个文件,也就是打开并处理完一个文件后再打开一个文件/*#include <iostream>using namespace std;int main(){ return 0;}*/// 第二十一章流 9 命令行处理文件//int main(int argc, char** argv) //是指向char的指针的指针//int main(int argc, char* argv[]) //字符数组的指针// argc是指命令输入参数的个数/*#include <iostream>using n 阅读全文
posted @ 2012-10-01 14:01 简单--生活 阅读(215) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 10使用命令行处理文件例程/*#include <iostream>#include <fstream>using namespace std;int main(int argc, char*argv[]){ if(argc==1) { cout<<"访程序"<<argv[0]<<"未操作文件名"<<endl; exit(EXIT_FAILURE); //exit()函数就是退出程序,传入的参数是程序退出时的状态码,0表示正常退出,其他表示非正常退出 } ifstr 阅读全文
posted @ 2012-10-01 14:01 简单--生活 阅读(153) 评论(0) 推荐(0) 编辑
摘要: // 第二十一章流 5 多种打开文件的方式 文件存在,文件不存在/*ios::in 打开文件进行读操作,即读取文件中的数据ios::out 打开文件进行写操作,即输出数据到文件中ios::ate 打开文件时针指向文件末尾,但是你可以在文件中的任何地方写入数据ios::app 打开文件不会清空数据,文件指针始终在文件尾,因此只能文件尾写数据ios::trunc 默认,若打开文件已经存在,则清空文件内容ios::nocreate 若打开文件不存在则不建立,返回打开失败信息ios::noreplace 打开文件时不能覆盖,若文件存在则返回打开失败信息ios::binary 打开文件为二进制文件,否则 阅读全文
posted @ 2012-10-01 14:00 简单--生活 阅读(423) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 6检查文件是否打开// // 使用布尔函数eof() bad() fail()他good()够检查// eof()/bad()/fail()返回假时或者 good()返回真时文件打开成功/*#include <iostream>#include <fstream>using namespace std;int main(){ ofstream fout("a.txt"); fout<<"输出到文件"; fout.close(); ifstream fin("a.txt"); if( 阅读全文
posted @ 2012-10-01 14:00 简单--生活 阅读(233) 评论(0) 推荐(0) 编辑
摘要: // 第二十一章流 7二进制文件和文本文件//1 以文本形式输出到文件/*#include <iostream>#include <fstream>using namespace std;//定义一个结构体peopleconst int num=20;struct people{ char name[num]; double weight; int tall; int age; char sex;};int main(){ people pe={"李能",78.5,181,25,'f'}; ofstream fout("pe 阅读全文
posted @ 2012-10-01 14:00 简单--生活 阅读(225) 评论(0) 推荐(0) 编辑
摘要: // 第二十一章流 1流的操作// 1.1 缓冲// 1.2 流和缓冲区// 1.3 标准输入输出对像// 1.4 重定向 重定向的意思是可以重新定向输出的设备// 1.5 对像代表流// 2.0 用count输出/*#include <iostream>using namespace std;int main(){ char *ch = "hello world"; //用强制转换方式将char*指针ch转换为void*之后,输出的就是字符串ch的地址,也就是第一个字符的位置 cout<<(void*)ch<<endl; //输出的&a 阅读全文
posted @ 2012-10-01 13:59 简单--生活 阅读(344) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 3用cin输入// 1 字符串的输入/*#include <iostream>using namespace std;int main(){ int x; cin>>hex>>x; cout<<x; system("pause"); return 0;}*/// 2 字符串的输入问题/*#include <iostream>using namespace std;int main(){ char word[12]; cin>>word; cout<<word<< 阅读全文
posted @ 2012-10-01 13:59 简单--生活 阅读(357) 评论(0) 推荐(0) 编辑
摘要: // 第二十一章流 4文件的输入和输出// 1输出数据到文件 //(1)包含fstream头文件 //(2)建立ofstream对像 如: ofstream ocout //(3)将对像与文件关联 ocout.open('123.txt'); //(4)该对像可看作cout对像,因此我们使用该对像将数据输出到文件中,而不是屏幕中 ocout<<"abc"; //(5)关闭与文件的连接 count.close();/*#include <iostream>#include <fstream>using namespace s 阅读全文
posted @ 2012-10-01 13:59 简单--生活 阅读(237) 评论(0) 推荐(0) 编辑
简单--生活(CSDN)