zoukankan      html  css  js  c++  java
  • C++ primer第一章 C++概述 纪要

    使用coutcin要包含:

    #include <iostream>

    using namespace std;

    注意C++库文件都定义在名称空间std来防止名字污染,不同公司编写的库也会使用特有的名字空间来防止库污染(函数名称冲突)。

    预编译指令的作用:

    //防止头文件被重复包含的预编译指令

    #ifndef BOOKSTORE_H

    #define BOOKSTORE_H

    #endif

     

    //用于调试

    #ifdef DEBUG

         cout<<"rendIn/n";

    #endif

     

    预定义的内部宏

    //C++编译器和C编译器提供兼容支持

    #ifdef __cplusplus

         extern "C"

    #endif

             int min(int,int);

    //用于输出调试信息

    int element_count=0;

    if(element_count==0)

    {

         cout<<"Error:"<<__FILE__<<endl<<":line "<<__LINE__<<" element count must be none zero";

    }

    #include <cassert>(C++头文件) #include <assert.h>(C头文件)

    int filename=0;

    assert(filename!=0);

    assert语句做了一个断言,应为后续程序执行的必须条件。

    VS 2008编译,断言失败,显示:

    文件输入输出:

    #include <fstream>

         ofstream outfile("out.txt");

         ifstream infile("in.txt");

     

         if(!infile)

         {

             cerr<<"Failed to open the infile.";

         }

         if(!outfile)

         {

             cerr<<"Failed to open the outfile.";

         }

         char word;

         while(infile>>word)

         {

             outfile<<word<<' ';

         }

         char ret;

         cin>>ret;

    cerrcout的功能是相同的,只不过它是专门用来输出错误信息的。

  • 相关阅读:
    服务器端事件发送SSE
    Mybatis generator代码生成
    如何靠谱地查到Tomcat的版本
    java自动生成代码
    Java读取excel(兼容03和07格式)
    常见的NoSQL数据库
    任务五 通用类问题相关度计算实现
    任务四 娱乐相关节目和娱乐人物关系代码整理
    任务三 非人物分析判断
    任务二 人物类与娱乐类关联优化分析
  • 原文地址:https://www.cnblogs.com/oyjj/p/2132989.html
Copyright © 2011-2022 走看看