
C++ Primer
文章平均质量分 63
sergery
这个作者很懒,什么都没留下…
展开
-
当给16位的unsigned short 对象赋值100000,赋的值是什么?
习题2.4,P11.// ------16位unsigned short : 最大是65535 ( 即2^16-1)unsigned short z;int x = 100 000 用十六进制表示是 : 0X186A0, 它的低十六位是 86A0 ,对应十进制的34464z赋值100 000 就会越界,编译器 截取 100 000 的二进制的低16位86A0赋予x,把高位原创 2012-11-10 12:27:01 · 4939 阅读 · 0 评论 -
C++,ifstream对象调用getline按行读取文本文件
C++ Prime P255 本来是学习该页的用 vector files #include #include #include #include using namespace std;void main(){ ifstream input; string s,filename = "c:/ludashi.txt"; vector files;原创 2012-11-17 16:57:31 · 42335 阅读 · 0 评论 -
编写一函数,形参返回值都是istream&类型...直到遇到EOF
P249,习题8.3// 标准IO库.cpp//P245#include using namespace std;istream& fun(istream& in){ int n; while(in>>n,!in.eof()){ if(in.bad()) // 系统级别故障,不可恢复,流不能继续使用,只能退出 throw ru原创 2012-11-17 15:16:26 · 4046 阅读 · 1 评论 -
将文件每一行读入到string类型的vector 对应一个元素中
C++Primer 习题8.9, P102书 P254#include #include #include #include using namespace std;void main(){ string s,filename = "c:/ludashi.txt"; vector svect; ifstream infile(filename.c_st原创 2012-11-17 18:35:57 · 6198 阅读 · 2 评论 -
const定义的全局变量不能被其他文件访问,必须加extern 才能被访问吗?
const定义的全局变量不能被其他文件访问,必须加extern 才能被访问吗?C++ Prime 中文版第四版 P50, 拍个照,上图: 测试表明不加extern 也是可以的啊:头文件就定义了3个变量,没有其他定义和申明. // ---------------------------------------------------------原创 2012-12-29 13:50:52 · 4939 阅读 · 4 评论 -
C风格字符串结束符用作逻辑判断
C 语言中0有几个用途。它是一个数字量;在字符串中它是一个结束符(’\0’),它是地址指针所允许的最小值;在逻辑表达式中它表示假,因为它有这么多的用途,你在编程时要清楚地表明是哪种。 C++ Prime P113--115#include #include using namespace std;void main(){char *cp = "hel0lo"原创 2012-12-30 19:13:20 · 2028 阅读 · 0 评论 -
C++ 容器vector 语法练习
编程不是什么技术活,就是个手工活,常常练习,否则手很生. 前面写个一次,很久不用就忘记了. http://blog.youkuaiyun.com/sergery/article/details/8144354 // C++ Prime 习题3.17 P31// 熟悉下容器操练语法#include #include using namespace std;vo原创 2013-01-01 15:31:36 · 1645 阅读 · 0 评论