• 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

  • 相关阅读:
    Linux入门-ssh scp rsync
    Linux入门-samba
    Linux入门-vsftp
    Linux入门-nfs
    MySQL卸载(rpm)
    rust_3_所有权
    rust_1_入门指南与猜猜看游戏
    vscode首次ssh remote linux连不上
    vbox新装ubuntu虚拟机注意事项
    IBM Rational Rose和Start UML的c++逆向工程自动生成UML类图组件
  • 原文地址:https://www.cnblogs.com/cplinux/p/5598246.html
Copyright © 2020-2023  润新知