posts - 6,comments - 2,trackbacks - 0

//string.h
#ifndef STRING_H_
#define STRING_H_
#include <iostream>
#include <cstring>
#include <cctype>
#include <cassert>
#include <cstddef>
#include <string>
#include "auto_pointer.h"

class String
{
private:
 size_t  _size;
 char *_string;
 void init (size_t , const char *);
public:
 String () { init (0, NULL); }
 String (const char * str) { init (strlen(str), str); }
 String (const String & str) { init (str.size (), str.c_str());}
 ~String () { delete [] _string; }
 //member methods
 int count (char ch)const;
 size_t size ()const { return _size; }
 char * c_str ()const {return _string ;}
 const char * to_upper ()const;
 //assign operator
 String & operator = (const char * str);
 String & operator = (const String & str);
 //overload operators
 bool operator == (const char *str)const {return strcmp (_string, str) == 0; }
 bool operator == (const String &str)const {return strcmp (_string, str.c_str ()) == 0; }
 bool operator != (const String & str)const { return strcmp (_string, str.c_str ()) != 0; }
 bool operator != (const char *str)const {return strcmp (_string, str) != 0; }
 bool operator < (const char *str)const {return strcmp (_string, str) < 0; }
 bool operator < (const String & str)const {return strcmp (_string, str.c_str ()) < 0; }
 bool operator > (const char *str)const {return strcmp (_string, str) > 0; }
 bool operator > (const String & str)const {return strcmp (_string, str.c_str ()) > 0; }
 String &  operator += (const char *str);
 String  & operator += (const String & str);
 char & operator [] (size_t i) { assert(i >= 0 && i < _size); return _string[i]; }
 //friend methods
 friend std::ostream & operator << (std::ostream & os, const String & str);
 friend std::istream & operator >> (std::istream &is, String & str);
 friend bool operator == (const char *cstr, const String & sstr) {return sstr.operator == (cstr); }
 friend bool operator != (const char *cstr, const String & sstr) {return sstr.operator != (cstr); }
 friend bool operator < (const char *cstr, const String & sstr) {return sstr.operator <(cstr); }
 friend bool operator > (const char *cstr, const String & sstr) {return sstr.operator >(cstr); }
};

#endif
//string.cpp
#include "String.h"
#include <cstring>
#include <iomanip>
#pragma warning(disable : 4996)

void String::init(size_t size, const char *str)
{
 _size = size;
 if (!str)
 {
  _string = new char [1];
  _string[0]  = '\0';
 }
 _string = new char[_size + 1];
 strncpy (_string, str, _size);
 _string[_size ] = '\0';
 //strcpy (_string, str);
}

String & String::operator = (const char *str)
{
 delete [] _string;
 init (strlen (str), str);std::cout << this->_string << "_";
 return *this;
}

String & String::operator = (const String &str)
{
 if (*this == str)
  return *this;
 delete [] _string;
 init (str.size (), str.c_str ());
 return *this;
}

String  & String::operator +=(const char *str)
{
 String temp(*this);
 _size += strlen (str);
 _string = new char[_size + 1];
 strcpy (_string, temp.c_str ());
 //strcat (_string, str);
 strcpy (_string+temp.size (), str);
 return *this;
}

String & String::operator +=(const String &str)
{
 String temp(*this);
 _size +=  str.size ();
 _string = new char[_size + 1];
 strcpy (_string, temp.c_str ());
 //strcat (_string , str.c_str ());
 strcpy (_string+temp.size (), str.c_str ());
 return *this;
}

int String::count (char ch)const
{
 int cn = 0;
 for (size_t i = 0; i < _size; i++)
  if (ch == tolower(_string[i]))
   cn++;
 return cn;
}

const char * String::to_upper ()const
{
 size_t size = strlen (_string);
 char *temp = new char[size + 1]; 
 size_t j = 0;
 for (size_t i = 0; i < size; i++)
  if (isalpha(_string[i]) || _string[i] == ' ')
   if (isalpha (_string[i]))
    temp[j++] = toupper (_string[i]);
   else
    temp[j++] = _string[i];
 temp[j] = '\0';
 return temp;
}
std::ostream & operator << (std::ostream & os, const String & str)
{
 return os << str.c_str ();
}

std::istream & operator >> (std::istream & is, String & str)
{
 const int limit_string_size = 50;
 char Inbuf [limit_string_size];

 //is.read (Inbuf, limit_string_size);
 //is >> setw (limit_string_size) >> Inbuf;
 is.getline (Inbuf, limit_string_size-1, '\n');
 /*if (is)
 {
  while (is.get () == '\n')
   break;
  Inbuf[limit_string_size-1] = '\0';
 }*/
 //is >> Inbuf;
 str = Inbuf;
 return is;
}

posted @ 2006-04-11 20:35 Jonathan 阅读(377) | 评论 (0)编辑 收藏

//头文件
#ifndef MYLIST_H_
#define MYLIST_H_
#include <iostream>

//declarations
template <typename elemType>
class Mylist_item
{
private:
 elemType _value;
 Mylist_item *_next;
public:
 Mylist_item (elemType value, Mylist_item * item = 0);
 ~Mylist_item () { }
 elemType Value () {return _value; }              //return the value of the node
 Mylist_item * Next () { return _next; }               //return the pointer to the next node
 void next (Mylist_item *ptr) { _next = ptr; }
 void set_value (elemType value ) { _value = value; }
};

template <typename elemType>
class Mylist
{
private:
 Mylist_item<elemType> *_at_front;                  //pointer to the head
 Mylist_item<elemType> *_at_end;                   //pointer to the tail
 Mylist_item<elemType> *_current;                   //pointer to the current element
 int _size;
 //renew the size
 void bump_up_size () { ++_size; }
 void bump_down_size () { --_size; }
public:
 Mylist () : _at_front (0), _at_end (0), _size (0) { }
 Mylist (const Mylist & rhs);
 ~Mylist () { }
 Mylist & operator = (const  Mylist  & rhs);

 //operators overloading
 Mylist_item<elemType> * operator ++ ();
 //Mylist_item<elemType> *operator ++ ();

 //sorting function (default in ascending order
 void sort (Mylist_item<elemType> *begin, Mylist_item<elemType> *end);

 //insertion functions, if the Mylist is full, do nothing

 //insert the value to the back of ptr
 void insert (Mylist_item<elemType> *ptr, elemType value);
 //insert the value to the front of the Mylist
 void insert_front (elemType value);
 //insert the value to the end of the Mylist
 void insert_end (elemType value);
 //insert the whole Mylist: rhs to the end of the current Mylist
 void insert_all (const Mylist & rhs);

 //element removing functions,  if the Mylist is empty , do nothing

 //remove all the elements of the Mylist equal to the value and return the numbers of removed elements
 int remove (elemType value);
 //remove all the elements of the Mylist
 void remove_all ();
 //remove the front element of the Mylist
 void remove_front ();

 //find the value that given, if successful, return the pointer to the element, or return null
 Mylist_item<elemType> * find (elemType value, Mylist_item<elemType> *start = 0);
 
 //display all the elements of the Mylist on screen
 void display (std::ostream & os = std::cout)const;

 //concat the given Mylist to the current Mylist
 void concat (const Mylist & rhs);
 Mylist  concat_copy (const Mylist &rhs);

 // reverse the Mylist, front to end
 void reverse ();
 Mylist reverse_copy ();

 //iterators
 Mylist_item<elemType> * init_iter (Mylist_item<elemType> *it = 0);
 Mylist_item<elemType> * next_iter ();

};

//definitions
template <typename elemType>
Mylist_item<elemType>::Mylist_item(elemType value, Mylist_item<elemType> *item)
{
 _value = value;
 if (!item)
  _next = 0;
 else
 {
  _next = item->Next ();
  item->_next = this;
 }
}

template <typename elemType>
Mylist<elemType>::Mylist (const Mylist & rhs): _at_front (0), _at_end (0)
{
 insert_all (rhs);
}

template <typename elemType>
Mylist<elemType> & Mylist<elemType>::operator =(const Mylist<elemType> &rhs)
{
 if (this == & rhs)
  return *this;
 remove_all ();
 insert_all (rhs);
 return *this;
}

template <typename elemType>
Mylist_item<elemType> * Mylist<elemType>::operator ++ ()
{
 return next_iter ();
}

/*template <typename elemType>
Mylist_item <elemType> * Mylist<elemType>::operator ++ ()
{
 Mylist_item<elemType> * temp = this;
 this = next_iter ();
 return temp;
}*/

template <typename elemType>
Mylist_item<elemType> * Mylist<elemType>::init_iter (Mylist_item<elemType> *it)
{
 return _current = it ? _current : _at_front;
}

template <typename elemType>
Mylist_item<elemType> * Mylist<elemType>::next_iter()
{
 Mylist_item<elemType> * temp = _current ? _current = _current->Next () : _current;
 return temp;
}

template <typename elemType>
void Mylist<elemType>::reverse ()
{
 Mylist_item<elemType> *ptr = _at_front;
 Mylist_item<elemType> *pre = 0;
 _at_front = _at_end;
 _at_end = ptr;
 while (ptr != _at_front)
 {
  Mylist_item<elemType> *temp = ptr->Next ();
  ptr->next (pre);
  pre = ptr;
  ptr = temp;
 }
}

template <typename elemType>
Mylist<elemType> Mylist<elemType>::reverse_copy ()
{
 Mylist<elemType>new_list;
 Mylist_item<elemType> *ptr = _at_front;
 for (; ptr ; ptr = ptr->Next ())
  new_list.insert_front (ptr->Value ());
 return new_list;
}

template <typename elemType>
void Mylist<elemType>::concat(const Mylist<elemType> &rhs)
{
 Mylist_item<elemType> * temp = rhs._at_front;
 while (temp)
 {
  insert_end (temp->Value ());
  temp = temp->Next ();
 }
}

template <typename elemType>
Mylist<elemType> Mylist<elemType>::concat_copy (const Mylist<elemType> & rhs)
{
 Mylist<elemType>new_list;
 Mylist_item<elemType> *ptr = _at_front;
 while (ptr)
 {
  new_list.insert_end (ptr->Value ());
  ptr = ptr->Next ();
 }
 for (ptr = rhs._at_front; ptr; ptr = ptr->Next ())
  new_list.insert_end (ptr->Value ());
 return new_list;
}

template <typename elemType>
void Mylist<elemType>::display(std::ostream &os) const
{
 os << " \n( " << _size << " ) ( ";
 Mylist_item<elemType> * ptr = _at_front;
 while (ptr)
 {
  os << ptr->Value () << " ";
  ptr = ptr->Next ();
 }
}

template <typename elemType>
Mylist_item<elemType> * Mylist <elemType>::find(elemType value, Mylist_item<elemType> *start)
{
 Mylist_item<elemType> *ptr = start ?start : _at_front;
 while (ptr)
 {
  if (ptr->Value () == value)
   break;
  ptr = ptr->Next ();
 }
 return ptr;
}

template <typename elemType>
int Mylist<elemType>::remove(elemType value)
{
 Mylist_item<elemType> *ptr = _at_front;
 int count = 0;
 while (ptr && ptr->Value () == value)
 {
  ptr = ptr->Next ();
  remove_front ();
  ++count;
 }
 if (!ptr)
  return count;
 Mylist_item<elemType> * pre = ptr;
 ptr = ptr->Next ();
 while (ptr)
 {
  if (ptr->Value () == value)
  {
   if (_current == ptr)
    _current = ptr->Next ();
   pre->next (ptr->Next ());
   ++count;
   delete ptr;
   bump_down_size ();
   ptr = pre->Next ();
  }
  else
  {
   pre = ptr;
   ptr = ptr->Next ();
  }
 }
 return count;
}

template <typename elemType>
void Mylist<elemType>::remove_front ()
{
 if (_at_front)
 {
  Mylist_item<elemType> * temp = _at_front;
  if (_current == _at_front)
   _current = _at_front->Next ();
  _at_front = _at_front->Next ();
  bump_down_size ();
  delete temp;
 }
}

template <typename elemType>
void Mylist<elemType>::remove_all ()
{
 while (_at_front)
  remove_front ();
 _size = 0;
 _at_front = _at_end = 0;
}

template <typename elemType>
void Mylist<elemType>::insert(Mylist_item<elemType> *ptr, elemType value)
{
 if (!ptr)
  insert_front (value);
 else
 {
  bump_up_size ();
  new Mylist_item<elemType>(value, ptr);
 }
}

template <typename elemType>
void Mylist<elemType>::insert_front(elemType value)
{
 Mylist_item<elemType> *ptr = new Mylist_item<elemType> (value);
 if (!_at_front )
  _at_front = _at_end = ptr;
 else
 {
  ptr->next (_at_front);
  _at_front = ptr;
 }
 bump_up_size ();
}

template <typename elemType>
void Mylist<elemType>::insert_end(elemType value)
{
 Mylist_item<elemType> *ptr = new Mylist_item<elemType> (value);
 if (!_at_end)
  _at_front = _at_end = ptr;
 else                    //_at_end = new Mylist_item<elemType> (value, _at_front);
 {
  _at_end->next (ptr);
  _at_end = ptr;
 }
 bump_up_size ();
}

template <typename elemType>
void Mylist<elemType>::insert_all(const Mylist<elemType> &rhs)
{
 Mylist_item<elemType> *ptr = rhs._at_front;
 while (ptr)
 {
  insert_end (ptr->Value ());
  ptr = ptr->Next ();
 }
}
#endif

//main () 函数

#include <iostream>
#include "Mylist.h"

int main()
{
 using std::cout;
 using std::endl;

 Mylist<int>mylist;

 for (int i = 0; i < 10; ++i)
 {
  mylist.insert_front (i);
  mylist.insert_end (i);
 }

 cout << "\nUse of init_iter() and next_iter () "
  << " to iterater across each Mylist item:\n";

 Mylist_item<int> *iter;
 //for (iter = mylist.init_iter (); iter; iter = mylist.next_iter ())
 for (iter = mylist.init_iter (); iter; iter = mylist++)
  cout << iter->Value () << " ";

 cout << "\nUse of copy constructor\n";

 Mylist<int> mylist2 (mylist);
 mylist.remove_all ();

 for (iter = mylist2.init_iter (); iter; iter = mylist2.next_iter ())
  cout << iter->Value () << " ";

 cout << " \nUse of copy assignment operator\n";
 mylist = mylist2;

 for (iter = mylist.init_iter (); iter; iter = mylist.next_iter ())
  cout << iter->Value () << " ";
 cout <<endl;

 cout << "\nUse of reverse_copy function:\n";
 Mylist<int>mylist3 = mylist.reverse_copy ();

 for (iter = mylist3.init_iter (); iter; iter = mylist3.next_iter ())
  cout << iter->Value () << " ";

 cout << "\nUse of concat_copy function:\n";
 mylist.remove (3);
 mylist.insert (mylist.init_iter (),16);
 mylist2 = mylist3.concat_copy (mylist);
 mylist2.display ();
 
 return 0;
}

posted @ 2006-04-11 20:33 Jonathan 阅读(813) | 评论 (0)编辑 收藏

#ifndef N_GRID_H_
#define N_GRID_H_
#include <cassert>
#include <iostream>

template <typename Type, int N>
class N_Grid
{
public:
 //constructors and destructors
 N_Grid ();
 N_Grid (int size);
 N_Grid (const N_Grid<Type, N> & );
 ~N_Grid ();
 //member methods
 N_Grid<Type, N> & operator = (const N_Grid<Type, N> & );
 void resize (int size );
 N_Grid<Type, N-1> & operator [] (int i);
 const N_Grid<Type, N-1> & operator [] (int i)const ;
 void print (std::ostream & os = std::cout)const;
 int get_size ()const { return _size; }
 static const int _Default_size = 10;
protected:
 void copy_from (const N_Grid<Type, N> & ); 
 int _size;
 N_Grid<Type, N-1> *_elem;
};
//definitions

template <typename Type, int N>
N_Grid<Type, N>::N_Grid(): _size (_Default_size)
{
 _elem = new N_Grid<Type, N-1> [_size];
}

template <typename Type, int N>
N_Grid<Type, N>::N_Grid(int size) : _size (size)
{
 _elem = new N_Grid<Type, N-1> [_size];
 //Allocate the array above calls the 0-argument
 //constructor for the N_Grid<Type, N-1>, which
 //constructs it with the default size.
 for (int i = 0; i < _size; i ++)
  _elem[i].resize (_size);
}

template <typename Type, int N>
N_Grid<Type, N>::N_Grid(const N_Grid<Type,N> & n_grid)
{
 copy_from (n_grid);
}

template <typename Type, int N>
N_Grid<Type, N>::~N_Grid ()
{
 delete [] _elem;
}

template <typename Type, int N>
void N_Grid<Type, N>::copy_from(const N_Grid<Type,N> & n_grid)
{
 _size = n_grid._size;
 _elem = new N_Grid<Type, N-1> [_size];
 for (int i = 0; i < _size; i++)
  _elem[i] = n_grid._elem [i];
}

template <typename Type, int N>
N_Grid<Type, N> & N_Grid<Type, N>::operator =(const N_Grid<Type,N> & n_grid)
{
 if (this == &n_grid)
  return *this;
 delete [] _elem;
 copy_from (n_grid);
 return *this;
}

template <typename Type, int N>
void N_Grid<Type, N>::resize(int size)
{
 N_Grid<Type, N> temp (*this);
 _size = size;
 _elem = new N_Grid<Type, N-1> [_size];
 for (int i = 0; i < _size && i < temp._size; i++)
 {
  _elem[i] = temp._elem[i];
  //risize the nested Grid elements recursively
  _elem[i].resize (_size);
 }
}

template <typename Type, int N>
N_Grid<Type, N-1> & N_Grid<Type, N>::operator [](int i)
{
 assert (i >= 0 && i < _size);
 return _elem[i];
}

template <typename Type, int N>
const N_Grid<Type, N-1> & N_Grid<Type, N>::operator [](int i) const
{
 assert (i >= 0 && i < _size);
 return _elem[i];
}

template <typename Type, int N>
void N_Grid<Type, N>::print(std::ostream &os = std::cout) const
{
 for (int i = 0; i < _size ; i++)
  _elem[i].print ();
 os << '\n';
}

template <typename Type>
class N_Grid<Type, 1>
{
public:
 //constructors and destructors
 N_Grid ();
 N_Grid (int size);
 N_Grid (const N_Grid<Type, 1> & );
 ~N_Grid ();
 //member methods
 N_Grid<Type, 1> & operator = (const N_Grid<Type, 1> & );
 void resize (int size );
 N_Grid<Type, 1> & operator [] (int i);
 const N_Grid<Type, 1> & operator [] (int i)const ;
 void print (std::ostream & os = std::cout)const;
 int get_size ()const { return _size; }
 static const int _Default_size = 10;
protected:
 void copy_from (const N_Grid<Type, 1> & ); 
 int _size;
 N_Grid<Type, 1> *_elem;
};
template <typename Type>
N_Grid<Type, 1>::N_Grid() : _size (_Default_size)
{
 _elem = new Type [_size];
}

template <typename Type>
N_Grid<Type, 1>::N_Grid(int size) : _size (size)
{
 _elem = new Type [_size];
}

template <typename Type>
N_Grid<Type, 1>::N_Grid(const N_Grid<Type, 1> & grid)
{
 copy_from (grid);
}

template <typename Type>
N_Grid<Type, 1>::~N_Grid()
{
 delete [] _elem;
}

template <typename Type>
void N_Grid<Type, 1>::copy_from(const N_Grid<Type,1> & grid)
{
 _size = grid._size;
 _elem = new Type [_size];
 for (int i = 0; i < _size; i++)
  _elem[i] = grid._elem[i];
}

template <typename Type>
N_Grid<Type, 1> & N_Grid<Type, 1>::operator =(const N_Grid<Type,1> & grid)
{
 if (this == &grid)
  return *this;
 delete [] _elem;
 copy_from (grid);
 return *this;
}

template <typename Type>
void N_Grid<Type, 1>::resize(int size)
{
 N_Grid<Type, 1> temp (*this);
 _size = size;
 _elem = new Type[_size];
 for (int i = 0; i < _size; i++)
  _elem[i] = temp._elem[i];
}

template <typename Type>
N_Grid<Type, 1> & N_Grid<Type, 1>::operator [](int i)
{
 assert (i >= 0 && i < _size);
 return _elem[i];
}

template <typename Type>
const N_Grid<Type, 1> & N_Grid<Type, 1>::operator [](int i) const
{
 assert (i >= 0 && i < _size);
 return _elem[i];
}

template <typename Type>
void N_Grid<Type, 1>::print(std::ostream &os = std::cout) const
{
 for (int i = 0; i < _size; i++)
   os << _size;
 os << '\n';
}
#endif

posted @ 2006-04-11 20:29 Jonathan 阅读(408) | 评论 (0)编辑 收藏
怎么边学边忘呢?好郁闷呀!刚刚看过模板和STL还有泛型算法的,但是现在又不会了,真是郁闷呀,
现在真的感觉很茫然,都不知道接下来应该如何学习C++了,又加上时间比较紧张,没有同样喜欢的人互相勉励,真的是举步维艰呀
posted @ 2006-04-11 20:26 Jonathan 阅读(225) | 评论 (0)编辑 收藏
前段时间一直潜心看《C++ primer》,到现在为止终于接近尾声了,但说实话感觉并没有掌握多少,这本书确实是重在解析呀,有时候感觉都看晕了,但是我还是一直坚持着,现在感觉这本书确实很好,我还要再仔细研读,虽然他有些方面还是不完善吧,这是我的个人观点,比如有些句子就比较艰涩难懂,还有就是对于多重继承和io讲的不是很详细,必须结合别的书籍才能理解,别的有些东西就讲得比较繁琐,还有就是习题太少了,例题也不太好,总是用同一个例子。
posted @ 2006-04-03 21:11 Jonathan 阅读(186) | 评论 (0)编辑 收藏
http://www.ttian.net/forum/viewtopic.php?pid=12441
上面的是文章的出处, 下面是我从那个网页的拷贝:
虽然TTIAN里搞开发的人少之又少,但是这里毕竟是我网上唯一的家,所以有什么想法还是发到这里比较合适。我不准备说C++的任何技术,只想说明如何成为C++高手,只想告诉你什么书可以解决你的什么问题!
________________________________________________________

      经过十分漫长的C++学习过程,我总算完成了我自己的C++心愿,看完了我想看的所有C++书籍,回顾我C++的整个学习过程,颇有一些心得和经验,希望与各位分享,也希望给正处在摸索学习阶段的XDJM一点学习参考。
    首先看看我第一次接触编程语言,唔,那可能要追述上到世纪,在我小学4年纪的时候第一次接触到BASIC,那个时候学习这个东西完全是为了要爸爸给我买一台386,没想到的是,BASIC开启了我对于计算机的一切兴趣与追求。5年纪的时候参加少年的计算机奥赛,我用BASIC写的一个彩色立体可旋转移动的正方体拿了一个铜牌,从此计算机编程成为了最大的爱好,现在我还保留着源代码,是保存在一盘普通单放机的磁带上的,我估计很少有人用过录音机和串口的转换器吧,呵。我用BASIC写的第二个大程序是给我妈妈用的财务程序,初中二年纪的时候,我妈妈在单位做出纳,我总看到妈妈每天晚上拿个计算机算一堆表,所以我写了这个程序帮助妈妈快速完成她的工作,其实我的根本目的是为了一台打印机,因为这个程序,生成了简单的报表,她可以直接打印,当然为了这个便利,她必须花钱给我买一台当时还算价值不低的打印机。不过现在回顾起来,BASIC虽然是我编程的第一位启蒙老师,但是在我开始C++的学习之后,他确实使我我思想上产生了很大的困绕,主要是OOP思想,我花费了将近1年多的时间才真正体会到什么是OO!
    到了大学,我才真正开始系统的学习编程。在此之间走过一些歪路,比如高中的时候研究HACKING,之所以说学习hacking是条歪路,原因很简单,因为研究到一定的程度,没有十分稳固的编程基础,根本的无法继续深入学习。中国**联盟解体前,位列第三的kender给了我这方面很大的打击,从此我就退出了,从此对于hacking我就不闻不问,从此看到那些下三烂的货色也要学hacking,我就感到可笑。第一次接触的是C,没什么好说的,我C学的不好,因为我大二的时候经商去了,而且我觉得C能做的,我用BASIC都能做到,为什么要学C?当然那个时候我成绩真是北大的BBS...然后接触到的就是C++,教材的钱能的《C++程序设计》,这本书其实还是很不错的,不过很多看了两本名著的朋友都对这本书嗤之以鼻,也许是我天生很笨,在我看完了《C++PRIMER》后还经常番看《C++程序设计》。《C++程序设计》虽然出书的时候ANSI C++还没有确定下来,不过它还是含盖了C++所有语法,建议对C++感兴趣却又没有任何基础的人先从这本书开始,简单而高效,不要认为人家一上来就看《C++ PRIMER》或是《the c++ programming language》就觉得自己的档次很低,你要确信,你肯定能超过他!这本书课后习题在我看来是典型的结构化编程,即使到了CLASS,也全部可以用STRUCT代替。不过在这个阶段做习题十分必要,用处我不想敲了,推荐使用的编译器就是书中所说到的编译器(我忘记叫什么了:P)看完之后,如果你想说C++很简单的话,建议你在看完了《C++ PRIMER》或是《the c++ programming language》之后再说。这两本书都是基于标准C++的,十分苛求的说,后者对标准的兼容性稍差:)。对这两本书,我的看法是,如果你确实想仔细的学习,建议你看《C++ PRIMER》,如果你想跳过我将要写到的下面两本书的话,建议你看《the c++ programming language》。对这两本书,前者最高到中文第三版,因为第四版,后者到特别版。对于前者,我看后的感觉是它的优点在于解析,特别是函数,类,模板的解析,但是它并没有含盖C++的方方面面,后者就不是这样。实际上我并没有仔细看过后者,只是同学总是拿这本书上的问题来与我商量,所以有机会偷窥了几眼。暂定你选择的是前者继续学习,在看完后,也许你用C++编制普通的程序已经能够运用自如,但是你仍然应该会有很多问题和遗憾,比如,类继承,虚拟继承,类访问控制,类继承下的访问控制,还有虽然我已经对如何解析十分清楚,但是我仍然感觉我对语法掌握得不系统,遗憾的是,书中出现了很多的库函数,我为什么都不知道?这个时候建议你看看《标准C++宝典》,这本书对于语法正所谓事无巨细,一一道来啊,再就是回顾一下《C++ 程序设计》(钱能),对类的部分讲解的还是十分精辟的。在掌握了一切牢固的语法基础之后,我选择的下一步不是STL,而是IOSTREAM,原因之一是因为《C++ PRIMER》并没有把这一部分讲述的很好,对了,《C++ PRIMER》也没有把STL讲述的很好,所以我看《C++ PRIMER》的时候这些章节都跳过了,我的目标是不求知道,只求精通。对于IOSTREAM,我选的书是《Standard C++ IOStream and Locales》,我当时还是看的E文原版,事实证明,我错了,这本对于当时的我,难度突然拔的太高,所以在看完了第一章之后我就放弃了,只是暂时的搁置下来了。对了,忘记说,对于《C++ PRIMER》或是《the c++ programming language》的学习,你应该十分认真的选择编译器了,我推荐3个首选dev-cpp最高4.9.9.2,然后是vc.net(千万看清楚,不是vc6.0!),最后就是borland c++ builder-X,具体我就不介绍了,相信你学习到这一步,自己应该已经掌握很多的信息了.继续,下一步,我的选择是〈深入探索C++对象模型〉,我是在图书馆借阅的,现在也有电子版了,不过我看了以下,效果一般,但是可以和E文原版的电子版一起看。这本书看完。如果你是跟我一样,把《C++ PRIMER》翻烂掉,能把《深入探索C++对象模型》的知识要点全部背出来的话,我恭喜你,你的C++水平已经到中级了:)接下来,我的选择是对C++这门语言为我提供的所有服务设施通透的学习一边。说穿了,就是库函数,C++库函数分两部分,一部分来自C语言,一部分就是STL,对于C语言部分,我建议你可以买一本C++函数库的书,最近好象刚出了一本,不过我还没有机会看,我看的是〈C和C++代码精粹〉,里面把C语言部分的库函数分为3类,这本书我也就看了这3个章节,其他的东西我知道,看他做甚?而对于STL,你如果真想成为C++出类拔萃的高手,你应该看3本<<C++标准程序库>>  <<泛型编程与STL>>   <<STL源码剖析>>,第一本主要讲的是如何使用STL,第二本将STL的一些设计理念,并指导你进行泛型设计,所谓泛型说穿了就是指模板。看完这些书,如果你跟我一样,可以把STL全部重写一边的话,那么恭喜你,你已经成为C++准高手,这个时候我的选择是回过头去看《Standard C++ IOStream and Locales》,呵,现在才发现原来这本书这么简单!简直是naive!其实,我现在最想做的事情就是能够把IO全部重写一边,不过还没有找到合适的编译器下手,感觉应该用GCC比较好,还没开始研究,我也不清楚。好了,既然这么多本讲述C++技术的书籍你都搞完了,也不在乎多两本吧,呵呵。知道你应该看什么吗?你应该看看<exceotional c++>还有<effective c++>,这两本书都有more版,不算太难,最后可以看《高质量C++编程》,最后有一套练习题,做做,小菜一样。接下来我的选择是<C++编程思想> 〈设计模式〉 〈大规模C++程序设计〉(最后一本我最近才看完:P)这3本书可不讲什么语法,第一本实在没有必要介绍,似乎每一种语言的编程思想的的书籍都是说的如何用这门语言编程,第二本其实并不能说是针对C++,所有语言通用的一本书,关键是程序设计的方式,第三本被称为〈设计模式〉的C++实践篇,其意义毋庸多说。看完了吗?好吧,你应该选一个项目锻炼一下。如果你能在一个月内看完这所有的书,欢迎你加入ISS_SQL开发团队,这个就是我近期想做的事情,我就是想写一个自己的数据库。不过如果你不是外星人的话,我估计你不可能在一个月的时间内,看完我看了2年的书。对于我刚才说的SQL,我还在选人,说实在的,现在我的同学里,真的是没有几个人的技术能让我看的上的,哎,得一知己难啊!还是继续说编程,这个时候,你已经有了顶级的C++基础,想学什么不容易?JAVA,你学了一个月??开玩笑,我看了一个星期的书就开始做项目了!其实我觉得到了这个时候是一个面临选择的时候,一个是做UNIX下的开发,一个是做WINDOWS下的,不过我选择了第三条路,也就是我正在学的,算法,因为我的导师正在做973计划中的数据挖掘项目,所以我也沾光,因为是基与weka,所以我用java,这个B语言真弱智,我已经开始讨厌JAVA了,所以我才想用C++重写一个WEKA类的开源软件,不过我感觉用java写算法,的确不错。前段时间,我一个同学为了一个C#问题苦恼,问题粗略说来是GIS设备返回串,要进行处理,提取数据,因为串本身的复杂性,具体是怎么样的我也不知道,因为他的这个是商业项目。这个问题在C#下十分困难,连正则表达式都无能为力,所以我给他的建议是写一个自动机,也不知道他最后的处理方式,不过在java下,呵,大概不超过五十行代码吧。说远了。
    最后说说人的问题。有一点点浮躁的人建议你千万别想学C++,直接学VB或者C#算了,希望在浩方有个排名的人,我直接告诉你,你不应该学C++。
    关于C++的学习,我就说这么多,其实也感觉没有说什么,只是把我学习C++看的每一门书都罗列出来,虽有显摆之嫌,但也确实希望给那些如曾经的我一样迷茫的摸索者,那些希望学习C++且追求完美技术的人指一条明路。简单的说,你认真看完我上面说的所有书,你就是C++高手!
posted @ 2006-03-13 21:52 Jonathan 阅读(438) | 评论 (2)编辑 收藏
仅列出标题