diff --git a/.kdev4/study_cpp.kdev4 b/.kdev4/study_cpp.kdev4 new file mode 100644 index 0000000..58de3f2 --- /dev/null +++ b/.kdev4/study_cpp.kdev4 @@ -0,0 +1,19 @@ +[Buildset] +BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x12\x00s\x00t\x00u\x00d\x00y\x00_\x00c\x00p\x00p) + +[CMake] +Build Directory Count=1 +Current Build Directory Index-主机系统=0 + +[CMake][CMake Build Directory 0] +Build Directory Path=/home/hmtsai/projects/study_cpp/build +Build Type=Debug +CMake Binary=/usr/bin/cmake +CMake Executable=/usr/bin/cmake +Environment Profile= +Extra Arguments= +Install Directory= +Runtime=主机系统 + +[Project] +VersionControlSupport=kdevgit diff --git a/src/type/class/tdate.cpp b/src/type/class/tdate.cpp index 2ab7ec0..1fb9500 100644 --- a/src/type/class/tdate.cpp +++ b/src/type/class/tdate.cpp @@ -80,7 +80,9 @@ private: int main() { - Tdate date ( 21,10,2011 ); + Tdate date ( 31,12,2011 ); + date.printYear(); + date.nextDay(); date.printYear(); cout< +using namespace std; +int main(){ + int a[5],i,*pa=a; + for(i=0;i<5;i++){ + scanf("%d",pa); + pa++; + } + pa=a; + for(i=0;i<5;i++){ + printf("a[%d]=%d\n",i,*pa); + pa++; + } + return 0; +} diff --git a/src/type/ptr/Advanced/ptr_cstring.cpp b/src/type/ptr/Advanced/ptr_cstring.cpp new file mode 100644 index 0000000..b74dff1 --- /dev/null +++ b/src/type/ptr/Advanced/ptr_cstring.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +using namespace std; +void swapchar(char &a,char&b){ + char temp=a; + b=a; + a=temp; +} + +int reverse(char *string_in){ + int string_len=strlen(string_in); + char string_out[string_len]; + for(int i=0;i +using namespace std; +int main(){ + int num,*ptr; + cin>>num; + ptr = new int[num]; + for(int i=0;i>ptr[i]; + } + for(int i=1;i +#include +using namespace std; +void swap ( int *a,int *b ) +{ + int temp=*a; + *a=*b; + *b=temp; +} +int sortInt ( int *a,int *b,int *c ) +{ + /* + int list[4]={ *a,*b,*c }; + sort ( list+0,list+3 ); + *a=list[0]; + *b=list[1]; + *c=list[2]; + //这是一个神奇的方法 + */ + if ( a>b ) { + swap ( a,b ); + } + if ( a>c ) { + swap ( a,c ); + } + if ( b>c ) { + swap ( b,c ); + } + //这是一个正常的方法 + return 0; +} +int main() +{ + int a,b,c,*ptr_a=&a,*ptr_b=&b,*ptr_c=&c; + cin>>a>>b>>c; + sortInt ( ptr_a,ptr_b,ptr_c ); + cout< +#include +using namespace std; +int main() +{ + int num; + scanf ( "%d",&num ); + int array[num+1]; + int *ptr=array+1; + for ( int i=1; i<=num; i++ ) { + cin>>*ptr; + ptr++; + } + ptr=array+1; + for ( int i=1; i<=num; i++ ) { + printf ( "%d ",*ptr ); + ptr++; + } + return 0; +} diff --git a/src/type/ptr/Basic/doubleptr.cpp b/src/type/ptr/Basic/doubleptr.cpp new file mode 100644 index 0000000..aff0cc5 --- /dev/null +++ b/src/type/ptr/Basic/doubleptr.cpp @@ -0,0 +1,9 @@ +#include +using namespace std; +int a=10,*p=&a,**pp=&p; +int main(){ + cout<<"a="<