
C++/C 技术文章
文章平均质量分 50
御史大夫
十一哥
展开
-
构造函数初始化列表
以下所有程序在code::blocks中编译运行,使用GNU GCC compiler一、什么是构造函数初始化列表构造函数初始化列表以一个冒号开始,接着是以逗号分隔的数据成员列表,每个数据成员后面跟一个放在括号中的初始化式。例如:class MyClass{ public: MyClass():x(1),y(2){} private:原创 2012-11-03 11:50:01 · 1001 阅读 · 0 评论 -
赋值和拷贝构造函数
有程序:#include using namespace std;class ClassA{ public: ClassA(int i = 0) {x = i;} ClassA(const ClassA& t) { x = t.x; cout << "调用拷贝构造函数" << en原创 2012-12-05 23:38:05 · 1102 阅读 · 0 评论 -
C/C++文件之eof()
C/C++文件之eof()版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://tuhao.blogbus.com/logs/21306687.html在使用C/C++读文件的时候,一定都使用过eof()这个函数来判断文件是否为空或者是否读到文件结尾了,也会在使用这个函数的过程中遇到一些问题,如不能准确的判断是否为空或者是否到了文件尾,以至于有些人可能还会怀转载 2012-12-08 09:18:56 · 795 阅读 · 0 评论 -
C++ istream::peek()
功能:peek函数用于读取并返回下一个字符,但并不提取该字符到输入流中,也就是说,依然让该字符作为将要提取到输入流的下一个字符。例程:#include #include using namespace std;int main(){ string word; char c; int n; cout << "Please enter a word原创 2012-12-08 09:38:55 · 12754 阅读 · 1 评论 -
error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
string filename = "1.txt"; ifstream fin; fin.open(filename);上述语句会产生如下错误:error: no matching function for call to 'std::basic_ifstream::open(std::string&)原因是C++的string类无法作为open的参数。解决方案:原创 2012-12-15 23:23:21 · 24470 阅读 · 3 评论 -
convert 'std::vector<>::iterator {aka __gnu_cxx::__normal_iterator<*, std::vector<> >}' to '*' in in
错误程序:#include #include using namespace std;struct A{ int x; A(int y) {x = y;}};int main(){ A a(11217); vector V; V.push_back(a); vector::iterator it = V.begin();原创 2012-12-19 18:47:04 · 7669 阅读 · 0 评论 -
error: creating array of references( declaration of 'a' as array)
错误程序:#include using namespace std;void func(int& a[], int n){ for(int i = 0; i < n; i++) a[i]++;}int main(){ int a[3] = {1, 2, 3}; func(a, 3); cout << a[0] << ' ' <<原创 2012-12-19 17:02:53 · 9258 阅读 · 2 评论 -
vc6.0执行程序正确而debug版和release版运行错误
使用vc6.0直接执行程序和执行debug版本或release版本的程序在执行环境上有差异。vc6中调试运行时,默认的当前目录是工程.dsw文件所在的目录,而debug版或release版直接运行时,当前目录是exe所在的目录。比如有文件1.txt在dsw文件所在目录下而不在exe文件所在目录下,则用vc直接运行程序时能打开1.txt,但直接运行exe文件时打开失败。原创 2013-01-08 20:49:06 · 1566 阅读 · 0 评论 -
gets()
参考资料:点击打开链接原型:char * gets ( char * str );功能:通过标准输入(stdin)读入字符并存储到C类型的字符串,当检测到换行符或者文件结束符时停止读入。换行符和文件结束符不读入字符串中。'\0'自动添加到字符串的最后。参数str:str是指向一段内存空间的指针或者是字符数组的数组名,它指向所读入的字符串,注意str指向的内存空间中原原创 2013-01-12 15:31:48 · 768 阅读 · 0 评论 -
如何利用迭代器获取vector的最后一个元素
错误观点:通过vector::end()能获取指向最后一个元素的指针。实际上,通过上面的方法获取的是指向末尾元素再下一个位置的指针。例子:#include #include using namespace std;int main(){ vector Int; Int.push_back(1); Int.push_back(5); vecto原创 2012-11-21 20:36:07 · 19831 阅读 · 1 评论 -
fopen C++
fopen">FILE * fopen ( const char * filename, const char * mode );Open fileOpens the file whose name is specified in the parameter filename and associates it with a stream that can be ident转载 2012-12-04 18:47:53 · 1990 阅读 · 0 评论 -
MFC无法给组合框控件添加CString类成员变量
今天出现了这个问题,网上搜了很久,虽然没有找到直接的答案,但是获得了启发,解决了这个问题——其实只是自己刚入门所识有限。我原来设定组合框的类型为Drop List,下拉列表式组合框的编辑框是不能编辑的,因而不能添加字符串类,改为允许编辑的Dropdown即可。顺便介绍一下几种类型的组合框:1.简易组合框(Simple)简易组合框中的列表框是一直显示的,编辑框可以编辑。2.下拉式原创 2012-11-04 16:08:30 · 5249 阅读 · 1 评论 -
C++重载运算符
本文主要讲述加号运算符“+”,自增运算符“++”,流提取运算符运“>>”,流插入运算符"先给出Vector类:class Vector{ public: Vector(double a = 0, double b = 0) {x = a, y = b;} //构造函数 Vector(const Vector& v){x = v.x, y =原创 2012-11-05 20:27:28 · 981 阅读 · 0 评论 -
MFC程序出现“Debug Assertion Failed! File:dlgdata.cpp Line: 43 ”错误
运行程序时,弹出提示框出错的原因是,我删掉了一个编辑框,但是没有清除相应对话框类(***Dlg.h)和资源头文件(Resource.h)中的相关信息。我删除的编辑框的映射变量为“m_strOverflow”,在所有文件中查找这一关键词,注释掉相关语句,程序就能正常运行。原创 2012-11-07 09:36:06 · 6258 阅读 · 2 评论 -
MFC程序出现“Debug Assertion Failed! File:afx.inl Line:177”错误
程序运行时弹出提示框原因:数组访问越界。原创 2012-11-07 10:04:45 · 3246 阅读 · 0 评论 -
指针总结
1.指针的地址和指针上储存的地址。指针是储存地址的变量,而指针自身也有自己的地址。#include using namespace std;int main(){ int *p, a; p = &a; //将a的地址赋值给p,此时p储存a的地址 cout << "指针p的地址:" << &p << endl; cout << "指针p储存的地址:" << p << en原创 2012-10-02 20:01:34 · 655 阅读 · 0 评论 -
c++ vector使用下标赋值出错
有以下程序#include #include using namespace std;int main(){ vector v; v[0] = 1; return 0;}运行会出现内存非法操作的错误。症结在于“v[0] = 1”一句。一开始vector为空时,不能对其进行下标赋值。而要用push_back().以下程序#include #原创 2012-11-11 17:17:55 · 8032 阅读 · 1 评论 -
error LNK2001: unresolved external symbol _main
Win32 控制台应用程序需要 main 函数作为入口点。当链接器在附加到项目的任何文件中都找不到 main 函数时会返回此错误消息。加上main()函数即可原创 2012-11-11 23:38:46 · 509 阅读 · 0 评论 -
一个文件读写的简易例子
先在储存工程文件的文件夹中新建两个文件:in.txt和out.txt,分别用于存放需要读入的内容和写进的内容。例如在in.txt中输入a 1v 3.2d 0.2q 0w 12f 0.10 0运行程序#include using namespace std;int main(){ ifstream in; //输入流对象 ofst原创 2012-11-21 10:09:57 · 704 阅读 · 0 评论 -
error: expected unqualified-id before 'int'
出错现场: bool i, int j;将逗号改成分号即可。C/C++不能在同一条语句中定义不同类型的变量。原创 2013-02-06 21:18:39 · 16066 阅读 · 0 评论