原创 C++程序設計語言練習4.4

不假定任何字符具有一般性的值,我們可能得到更具有可移植性的代碼。 #include <iostream> #include <ctype.h> #include <iomanip> using std::cout; using std

原创 C++程序設計語言練習6.5

無定義行爲和由實現定義的行爲 C++語言的未定義情況集中在:    某些運算符的運算順序    直接使用未初始化的局部變量或對象中的值    直接使

原创 C++程序設計語言練習5.12 對比string和C字符串的優劣

我的代碼: #include <string> using std::string; int CountMatch(string MatchStr, string s) { int pos = 0; int tpos = 0;

原创 C++程序設計語言練習6.3 multimap標準庫的使用

代碼如下: #include <iostream> #include <map> #include <string> using std::cin; using std::cout; using std::multimap; using

原创 C++程序設計語言練習4.5

C++標準庫通過template  numeric_limits提供數值類型的極限值。使用這個模板,可以一定程度的提高程序的可移植性。 #include <iostream> #include <limits> using std::c

原创 C++程序設計語言練習6.14 字符串反轉

我的代碼如下: #include <iostream> #include <stdio.h> #include <string.h> using std::cout; char * rev(char * p) { unsigned

原创 C++程序設計語言練習6.10 字符串函數的寫法

自己寫的strlen和strcpy: unsigned int strlen(const char *s) { unsigned int count = 0; while(*s++ != '\0') count++; retu

原创 C++程序設計語言練習6.17 itoa 的實現

我的代碼如下: #include <iostream> using std::cout; void itoa(int i,char b[]) { // int figures = 0; int temp = i; // c

原创 C++程序設計語言練習5.8 編譯器對指針的優化

代碼如下: #include <iostream> using std::cout; int _tmain(int argc, _TCHAR* argv[]) { const int SIZE = 1000; int ia[SIZ

原创 C++程序設計語言練習5.7 結構體數組的初始化

代碼如下: #include <iostream> using std::cout; using std::cin; #define MONTHS 12 struct date{ char month[4]; int DayO

原创 C++程序設計語言練習5.3 typedef的使用

定義類型unsigned char定義類型const unsigned char定義類型到整數的指針定義類型到字符的指針的指針定義類型到字符數組的指針定義類型7個到整數的指針的數組定義類型到包含7個到整數的指針的數組的指針定義類型包含8

原创 C++程序設計語言練習5.2 內存對齊

1、棧內存對齊 #include <iostream> #include <cstdio> using std::cout; int main() { char ch1 = 'a'; int i1 = 1; char ch2

原创 C++程序設計語言練習5.6 變量的引用和常量引用

代碼如下: #include <iostream> using std::cout; void f(char a) { cout<<a; } void g(char& b) { cout<<b; } void h(const c

原创 C++程序設計語言練習5.11 map標準庫應用

代碼如下: #include <iostream> #include <map> #include <string> using std::cout; using std::cin; using std::map; using std

原创 C++程序設計語言練習6.16 atoi 的實現

我的代碼如下: #include <iostream> #include <stdio.h> using std::cout; enum redix{octonary = 8,decimal = 10 ,hexadecimal = 1