随笔分类 -  找错

摘要:给出输出结果:A,编译错误B,编译成功,运行错误C,编译正常,输出10#include <iostream>using namespace std;class A{private: int value;public: A(int a) { value =a; } A ( A other) { value =other.value; } void Print() { cout<<value<<endl; }};int main(){ A a = 10; A b = a; b.Print(); system("pause"); return 阅读全文
posted @ 2012-11-14 11:25 byfei 阅读(148) 评论(0) 推荐(0) 编辑
摘要:typedef vector IntArray;IntArray array;array.push_back( 1 );array.push_back( 2 );array.push_back( 2 );array.push_back( 3 );// 删除array数组中所有的2for( IntArray::iterator itor=array.begin(); itor!=array.end(); ++itor ){if( 2 == *itor ) array.erase( itor );}答:同样有缺少类型参数的问题。另外,每次调用“array.erase( itor );”,被删除元素 阅读全文
posted @ 2012-06-29 16:56 byfei 阅读(127) 评论(0) 推荐(0) 编辑
摘要:vector array;array.push_back( 1 );array.push_back( 2 );array.push_back( 3 );for( vector::size_type i=array.size()-1; i>=0; --i ) // 反向遍历array数组{cout << array[i] << endl;}答:首先数组定义有误,应加上类型参数:vector<int> array。其次vector::size_type被定义为unsigned int,即无符号数,这样做为循环变量的i为0时再减1就会变成最大的整数,导致循环 阅读全文
posted @ 2012-06-29 16:47 byfei 阅读(457) 评论(0) 推荐(0) 编辑
摘要:unsigned intconst size1= 2;char str1[ size1 ];unsigned int temp= 0;cin >> temp;unsigned intconst size2= temp;char str2[ size2 ];答:str2定义出错,size2非编译器期间常量,而数组定义要求长度必须为编译期常量。 阅读全文
posted @ 2012-06-29 16:45 byfei 阅读(232) 评论(0) 推荐(0) 编辑
摘要:试题1voidtest1(){charstring[10];char*str1="0123456789";strcpy(string,str1);}试题2voidtest2(){charstring[10],str1[10];inti;for(i=0;i<10;i++){str1[i]='a';}strcpy(string,str1);}试题3voidtest3(char*str1){charstring[10];if(strlen(str1)<=10){strcpy(string,str1);}}试题4: void GetMemory( cha 阅读全文
posted @ 2012-06-28 19:46 byfei 阅读(217) 评论(0) 推荐(0) 编辑