2012年11月21日

如何利用迭代器获取vector的最后一个元素

摘要: 错误观点:通过vector::end()能获取指向最后一个元素的指针。实际上,通过上面的方法获取的是指向末尾元素再下一个位置的指针。例子:#include <iostream> #include <vector> using namespace std; int main() { vector<int> Int; Int.push_back(1); Int.push_back(5); vector<int>::iterator it = Int.end(); cout << *it << endl; return 0; } 阅读全文

posted @ 2012-11-21 20:36 铁树银花 阅读(7669) 评论(0) 推荐(0) 编辑

一个文件读写的简易例子

摘要: 先在储存工程文件的文件夹中新建两个文件:in.txt和out.txt,分别用于存放需要读入的内容和写进的内容。例如在in.txt中输入a 1v 3.2d 0.2q 0w 12f 0.10 0运行程序 1 #include <fstream> 2 using namespace std; 3 4 int main() 5 { 6 ifstream in; //输入流对象 7 ofstream out; //输出流对象 8 char ch; 9 double w;10 in.open("in.txt"); //打开相应文件11 out.o... 阅读全文

posted @ 2012-11-21 10:09 铁树银花 阅读(202) 评论(0) 推荐(0) 编辑

导航