当前位置: 首页 > news >正文

网站中验证码如何做的长沙网络建站

网站中验证码如何做的,长沙网络建站,研发和开发的区别,wordpress的MD风格主题文章目录目录1.文件和流2.异常处理3.动态内存4.命名空间目录 1.文件和流 注意 文件打开方式中的in和out都是相对于内存#xff08;计算机#xff09;而言的#xff0c;计算机读取文件#xff0c;是将数据从磁盘中的文件读入到内存中#xff0c;所以用的是in #include 计算机而言的计算机读取文件是将数据从磁盘中的文件读入到内存中所以用的是in #include fstream #include iostream using namespace std;int main () {char data[100];// 以写模式打开文件ofstream outfile;outfile.open(afile.dat);cout Writing to the file endl;cout Enter your name: ; cin.getline(data, 100);// 向文件写入用户输入的数据outfile data endl;cout Enter your age: ; cin data;cin.ignore();// 再次向文件写入用户输入的数据outfile data endl;// 关闭打开的文件outfile.close();// 以读模式打开文件ifstream infile; infile.open(afile.dat); cout Reading from the file endl; infile data; // 在屏幕上写入数据cout data endl;// 再次从文件读取数据并显示它infile data; cout data endl; // 关闭打开的文件infile.close();return 0; }当上面的代码被编译和执行时它会产生下列输入和输出 $./a.out Writing to the file Enter your name: Zara Enter your age: 9 Reading from the file Zara 9 注意 流操作符也是相对于计算机而言的计算机是可以赋值和改变的左值在左边所以从外部读取数据到计算机内存中使用的流操作符是 同理从计算机内存中输出到其他设备屏幕使用的流操作符是 ,数据的方向是从内存到外部设备所以箭头朝右边非常形象。 #include iostream #include fstream using namespace std;//向文件内部写入数据并将数据读出 void file_wr(void) {char data[100];//向文件写入数据ofstream outfile;outfile.open(test.txt);cout Write to the file endl;cout Enter your name: endl;cin.getline(data, 100);outfile data endl;cout Enter your age: endl;cin data;cin.ignore();outfile data endl;outfile.close();//从文件读取数据ifstream infile;infile.open(test.txt);cout Read from the file endl;infile data;cout data endl;infile data;cout data endl;infile.close(); }//将数据从一文件复制到另一文件中 void file_copy(void) {char data[100];ifstream infile;ofstream outfile;infile.open(test.txt);outfile.open(test_1.txt);cout copy from test.txt to test_1.txt endl;while (!infile.eof()){infile data;cout data endl;outfile data endl;}infile.close();outfile.close(); }//测试上述读写文件与文件数据复制 int main() {file_wr();file_copy();return 0; }当上面的代码被编译和执行时它会产生下列输入和输出 $./a.out Writing to the file Enter your name: John Enter your age: 20 Reading from the file John 20 copy from test.txt to test_1.txt John 20 2.异常处理 #include iostream using namespace std;double division(int a, int b) {if( b 0 ){throw Division by zero condition!;}return (a/b); }int main () {int x 50;int y 0;double z 0;try {z division(x, y);cout z endl;}catch (const char* msg) {cerr msg endl;}return 0; }由于我们抛出了一个类型为 const char* 的异常因此当捕获该异常时我们必须在 catch 块中使用 const char*。当上面的代码被编译和执行时它会产生下列结果 Division by zero condition! 3.动态内存 #include iostream using namespace std;int main () {double* pvalue NULL; // 初始化为 null 的指针pvalue new double; // 为变量请求内存*pvalue 29494.99; // 在分配的地址存储值cout Value of pvalue : *pvalue endl;delete pvalue; // 释放内存return 0; }#include iostream using namespace std;int main() {int **p; int i,j; //p[4][8] //开始分配4行8列的二维数据 p new int *[4];for(i0;i4;i){p[i]new int [8];}for(i0; i4; i){for(j0; j8; j){p[i][j] j*i;}} //打印数据 for(i0; i4; i){for(j0; j8; j) { if(j0) coutendl; coutp[i][j]\t; }} //开始释放申请的堆 for(i0; i4; i){delete [] p[i]; }delete [] p; return 0; }0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 0 2 4 6 8 10 12 14 0 3 6 9 12 15 18 21 #include iostream using namespace std;class Box {public:Box() { cout 调用构造函数 endl; }~Box() { cout 调用析构函数 endl; } };int main( ) {Box* myBoxArray new Box[4];delete [] myBoxArray; // 删除数组return 0; }如果要为一个包含四个 Box 对象的数组分配内存构造函数将被调用 4 次同样地当删除这些对象时析构函数也将被调用相同的次数4次。 当上面的代码被编译和执行时它会产生下列结果 调用构造函数 调用构造函数 调用构造函数 调用构造函数 调用析构函数 调用析构函数 调用析构函数 调用析构函数 class A {private:char *m_cBuffer;int m_nLen;public:A(){ m_cBuffer new char[m_nLen]; }~A() { delete [] m_cBuffer; } }; A *a new A[10];// 仅释放了a指针指向的全部内存空间 但是只调用了a[0]对象的析构函数 剩下的从a[1]到a[9]这9个用户自行分配的m_cBuffer对应内存空间将不能释放 从而造成内存泄漏 delete a;// 调用使用类对象的析构函数释放用户自己分配内存空间并且 释放了a指针指向的全部内存空间 delete [] a;4.命名空间 本质上命名空间就是定义了一个范围。 #include iostream using namespace std;// 第一个命名空间 namespace first_space{void func(){cout Inside first_space endl;} } // 第二个命名空间 namespace second_space{void func(){cout Inside second_space endl;} } int main () {// 调用第一个命名空间中的函数first_space::func();// 调用第二个命名空间中的函数second_space::func(); return 0; }当上面的代码被编译和执行时它会产生下列结果 Inside first_space Inside second_space #include iostream using namespace std;// 第一个命名空间 namespace first_space{void func(){cout Inside first_space endl;} } // 第二个命名空间 namespace second_space{void func(){cout Inside second_space endl;} } using namespace first_space; int main () {// 调用第一个命名空间中的函数func();return 0; }当上面的代码被编译和执行时它会产生下列结果 Inside first_space using 指令也可以用来指定命名空间中的特定项目。例如如果您只打算使用 std 命名空间中的 cout 部分您可以使用如下的语句 using std::cout; #include iostream using namespace std;// 第一个命名空间 namespace first_space{void func(){cout Inside first_space endl;}// 第二个命名空间namespace second_space{void func(){cout Inside second_space endl;}} } using namespace first_space::second_space; int main () {// 调用第二个命名空间中的函数func();return 0; }当上面的代码被编译和执行时它会产生下列结果 Inside second_space
http://www.yutouwan.com/news/227801/

相关文章:

  • 淄博网站排名优化公司360阻止建设银行网站
  • 网站设计制作方案花垣做网站
  • 宝安各大网站制作比较好的网络营销的未来发展趋势
  • 现在网站一般做多大的天元建设集团有限公司蒙阴分公司
  • 网站做了泛解析 为什么影响seo上海保洁公司
  • 自己做网站不用WordPress国内优秀个人网站
  • 应该知道的网站wordpress 编辑器 代码高亮
  • 地方门户网站源码网络营销环境分析主要包括
  • 唐山网站制作工具电脑做微信推送的网站
  • 网站开发 高级认证自己免费建设网站
  • 张家界网站建设要求什么网站上公司的评价最客观
  • 公司网站用什么cms系统wordpress随机切换主页内容
  • 小榄镇做网站公司广告网络平台
  • 网站备案的意思思睿鸿途北京网站建设
  • 网站建设 类型没有服务器怎样做网站
  • 巨久科技网站建设科技厅
  • 桂林微信网站设计数据网站建设成本
  • 上海跨境电商网站制作wordpress .ds_store
  • 服务器做网站FTP必要性大吗做的网站如何改标题
  • 百度网站的主要盈利来源不包括做兼职网上哪个网站好
  • 手机网站域名解析怎么做网页制作素材小图片
  • 化妆品网站html模板天河区建设和水务局网站
  • 天津 公司做网站长春建站优化加徽信xiala5效果好
  • 对做的网站的改进建议前端做网站的步骤
  • 专注旅游网站网站开发如乐网站
  • 余姚市网站建设建站哪家好就要用兴田德润
  • 网线水晶头接法图解东莞seo网络营销
  • 带有flash的网站湖北华路建设工程有限公司网站
  • 最佳外贸建站平台在哪个网站做推广好
  • 网站维护内容和方法最新seo课程