C++编程思想读后感(二):Making and Using Objects
2011-05-31 16:15
417 查看
1、声明declaration和定义definition不一样。对于函数,如果引用不在当前文件定义或者当前文件尚未定义的函数,则需要预先声明该函数,声明中需指出函数名,返回值类型,参数个数和类型;函数定义和函数声明主要区别在于是否存在函数体(即使是空的)。
2、变量声明必须使用extern关键字,变量声明和变量定义的区别也就在于是否存在extern关键字。函数声明前用不用extern都可以。extern意思:This is only a declaration, it is defined elsewhere.
3、声明可以有多处,定义只能有一处
4、include<>和include""搜索的路径不一样,前者搜索系统路径,后者先从工程当前路径开始。include的头文件后缀名.h可以省略
5、几个基本的库:iostream,fstream,string,vector。下面是一个使用它们的例子:
2、变量声明必须使用extern关键字,变量声明和变量定义的区别也就在于是否存在extern关键字。函数声明前用不用extern都可以。extern意思:This is only a declaration, it is defined elsewhere.
3、声明可以有多处,定义只能有一处
4、include<>和include""搜索的路径不一样,前者搜索系统路径,后者先从工程当前路径开始。include的头文件后缀名.h可以省略
5、几个基本的库:iostream,fstream,string,vector。下面是一个使用它们的例子:
#include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; int main() { cout<<"a number in decimal:"<<dec<<15<<endl; cout<<"in octal:"<<oct<<15<<endl; cout<<"in hex:"<<hex<<15<<endl; cout<<"a floating-point number:"<<3.14159<<endl; cout<<"non-printing char(escape)"<<char(56)<<endl; int number; cout<<"/nEnter a number:"; cin>>number; cout<<"value in oct: "<<oct<<number<<endl; cout<<"value in hex: "<<hex<<number<<endl; vector<string> v; ifstream in("main.cpp"); string line; // while(getline(in,line)) //new line separated while(in>>line) //white space separated v.push_back(line); for(int i=1;i<=v.size();i++) cout<<i<<":"<<v[i-1]<<endl; return 1; }
相关文章推荐
- C++编程思想读后感(一):Introduction to Objects
- chap 2 making and using objects
- C++编程思想读后感(六):Initialization and Cleanup
- C++编程思想读后感(七):Function Overloading and Default Arguments
- Using and Understanding Java Data Objects
- Making and storing references to game objects (entities) in C++ and Lua
- Tailor Your DataGrid Apps Using Table Style and Custom Column Style Objects
- C++编程思想读后感(五):Hiding the Implementation
- Data Structures and Other Objects Using C++ (Chapter 1) 学习笔记一
- <iOS>enumerateKeysAndObjectsUsingBlock的用法
- Send and Receive JSON objects to Web Service Methods using jQuery AJAX in ASP.Net
- Generate Java objects for FpML using JAXB and Maven: The Easy Way!
- C++编程思想读后感(四):Data Abstraction
- Serialize and deserialize objects as Xml using generic types in C# 2.0
- C++编程思想读后感(八):Constants
- Data Structures and Other Objects Using C++ (Chapter 2) 学习笔记四
- Using Record Objects as Parameters and Returns
- A Data Access Layer to persist business objects using attributes and reflection - Part I
- A Data Access Layer to persist business objects using attributes and reflection - Part III [无常译]
- enumerateKeysAndObjectsUsingBlock 的用法