Come up and C++ me some time ~ (chapter 1~6)
2015-01-05 21:13
309 查看
Point 1: 变量初始化
C++98标准:
int emus= 5;
int emus= {5};
int emus(5);
C++11新增标准:
int emus[5]{1,2,3,4,5};
int emus{5};
int emus{}; //初始化为0
long plifs[]= {25,93,2.0}; // not allowed 列表初始化时禁止缩窄转换
char slifs[4]{'h','y',1122011,'\0'}; // not allowed ditto
C++11标准目前VS2008不支持
Point 2:浮点数
浮点数的表示方法:计算机将这样的值分成两部分存储。
一部分表示值,另一部分用于对值进行放大或缩小
如:数字34.1245和34124.5两个数除了小数点不同之外其他都是相同的。分解后得到基准值相同(0.341245),缩放因子分别为100、10000,其中缩放因子的作用是
移动小数点的位置,且缩放因子在C++中是2的幂表示。(对于float C++只保证6位有效位)
Point 3:强制类型转换
有符号整型级别由高到低依次是:long long --> long --> int --> short --> signed char
无符号整型级别排列顺序与有符号整型相同
Point 4:字符函数库 cctype
isalpha() //如果参数为字母则返回true
isdigit() //如果参数为数字则返回true
islower() //如果参数为小写字母则返回true
ispunct() //如果参数为标点符号则返回true
iscntrl() //如果参数为控制字符则返回true
Point 5:简单文件输入输出
写入至文本文件中:
#include <fstream>
int main(){
ofstream outFile;
outFile.open("text.txt");
if( outFile.is_open() ){
outFile<< "this is the operation to writing to the txt !"<< endl<< "end !";
}
outFile.close();
return 0;
}
从文本文件中写出:
#include <iostream>
#include <fstream>
int main(){
char contentFile[50]= {0};
ifstream inFile;
inFile.open("text.txt");
if( inFile.is_open() ){
inFile<< "this is the operation to reading from the txt !"<< endl<< "end !";
}
while(inFile.good()){
inFile>> contentFile;
cout<< contentFile<< endl;
}
outFile.close();
return 0;
}
C++98标准:
int emus= 5;
int emus= {5};
int emus(5);
C++11新增标准:
int emus[5]{1,2,3,4,5};
int emus{5};
int emus{}; //初始化为0
long plifs[]= {25,93,2.0}; // not allowed 列表初始化时禁止缩窄转换
char slifs[4]{'h','y',1122011,'\0'}; // not allowed ditto
C++11标准目前VS2008不支持
Point 2:浮点数
浮点数的表示方法:计算机将这样的值分成两部分存储。
一部分表示值,另一部分用于对值进行放大或缩小
如:数字34.1245和34124.5两个数除了小数点不同之外其他都是相同的。分解后得到基准值相同(0.341245),缩放因子分别为100、10000,其中缩放因子的作用是
移动小数点的位置,且缩放因子在C++中是2的幂表示。(对于float C++只保证6位有效位)
Point 3:强制类型转换
有符号整型级别由高到低依次是:long long --> long --> int --> short --> signed char
无符号整型级别排列顺序与有符号整型相同
Point 4:字符函数库 cctype
isalpha() //如果参数为字母则返回true
isdigit() //如果参数为数字则返回true
islower() //如果参数为小写字母则返回true
ispunct() //如果参数为标点符号则返回true
iscntrl() //如果参数为控制字符则返回true
Point 5:简单文件输入输出
写入至文本文件中:
#include <fstream>
int main(){
ofstream outFile;
outFile.open("text.txt");
if( outFile.is_open() ){
outFile<< "this is the operation to writing to the txt !"<< endl<< "end !";
}
outFile.close();
return 0;
}
从文本文件中写出:
#include <iostream>
#include <fstream>
int main(){
char contentFile[50]= {0};
ifstream inFile;
inFile.open("text.txt");
if( inFile.is_open() ){
inFile<< "this is the operation to reading from the txt !"<< endl<< "end !";
}
while(inFile.good()){
inFile>> contentFile;
cout<< contentFile<< endl;
}
outFile.close();
return 0;
}
相关文章推荐
- Come up and C++ me some time ~ (chapter 7~11)
- some different between array and Vector(C++) when trying to swap two element
- How to do run-time (or explicit) linking of C++ plug-in components and objects
- General failure in response to MSG_ENABLEDS,Low Memory Condition encountered,free up some memory and
- Summarizes chapter one of datastructures and program design in C++
- Data Structures (Weiss) Chapter 8: Union and Find, Disjoint Sets, union by sizes, C++
- C++ Primer notes: Chapter 2. Variables and Basic Types
- Data Structures and Other Objects Using C++ (Chapter 2) 学习笔记四
- Chapter 2: Connecting to C++ Methods and Signals
- Some VS2005 and VS2008 Wizards Pop Up Script Error(转)
- Data Structures and Other Objects Using C++ (Chapter 1) 学习笔记二
- Tom DeMarco的Software Engineering: An Idea Whose Time Has Come and Gone?摘要与感想
- Types and Declarations(Chapter 4 of The C++ Programming Language)
- Some Noteable Diffs Between C++ and C#
- Some VS2005 and VS2008 Wizards Pop Up Script Error
- Real-Time 3D Terrain Engines Using C++ and DirectX 9
- [转]Some VS2005 and VS2008 Wizards Pop Up Script Error
- Namespaces and Exceptions(Chapter 8 of The C++ Programming Language)
- IBM Rational Rose @ RealTime Timer的一些用法以及误差(some usages and deviations)
- Data Structures and Other Objects Using C++ (Chapter 1) 学习笔记三