1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cstdlib> 5 using namespace std; 6 class StringStack{ 7 static const int size = 100; 8 const string* stack[size]; 9 int index; 10 public: 11 StringStack(); 12 void push(const string* s); 13 const string* pop(); 14 15 }; 16 17 StringStack::StringStack() :index(0){ 18 memset(stack, 0, size*sizeof(string*)); 19 } 20 21 void StringStack::push(const string* s){ 22 if (index<size) 23 stack[index++] = s; 24 } 25 26 const string* StringStack::pop(){ 27 if (index>0){ 28 --index; 29 const string* rv = stack[index]; 30 stack[index] = 0; 31 return rv; 32 } 33 34 return 0; 35 36 } 37 38 string iceCream[] = { 39 40 "pralines & cream", "fudege ripple", "jamocha almond fudge", "wild mountain blackberry", 41 "raspberry sorbet", "lemon swirl", "rocky road", "deep chocolate fudge" 42 43 }; 44 45 const int iCsz = sizeof(iceCream) / (sizeof(*iceCream)); 46 47 int main(){ 48 49 StringStack ss; 50 for (int i = 0; i<iCsz; i++) 51 ss.push(&iceCream[i]); 52 const string* cp; 53 while ((cp = ss.pop()) != 0) 54 cout << *cp << endl;//报错: 55 system("pause"); 56 return 0; 57 58 59 }
2 IntelliSense: 没有与这些操作数匹配的 "<<" 运算符
操作数类型为: std::ostream << const std::string d:programmer practice hinking in c++ 8ConstInClassConstInClassconstInClass.cpp 61 8 ConstInClass