• const stirng* 类型的指针cp,当cout<<*cp<<endl:会提示没有与之匹配的“<<”运算符


     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

  • 相关阅读:
    异星觉醒观后感
    Word加密功能
    mysql基础
    Java学习笔记二—Java语法
    Java学习笔记一
    红帽考试学习第二十记
    红帽考试学习第十九记
    红帽考试学习第十八记
    红帽考试学习第十七记
    红帽考试学习第十六记
  • 原文地址:https://www.cnblogs.com/cplinux/p/5598246.html
Copyright © 2020-2023  润新知