首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

种 对象数组 字符串

2012-10-12 
类 对象数组 字符串C/C++ code#include iostream#include stringusing namespace stdclass lock{publ

类 对象数组 字符串

C/C++ code
#include <iostream>#include <string>using namespace std;class lock{public:    char w;    void print(char w)    {        cout<<w<<" ";    }};int main(){    string w;    cin>>w;    int size=w.size();    lock* locks = new lock[size];    for(int i=0;i<size;i++)        locks[i].print;}

意思是用一个类的对象数组接收一串未知长度的字符串.然后通过类里面的"print"函数逐个输出.请问该怎么改呢???

[解决办法]
locks[i].print(w[i])就行了,因为string重载了[]符号、。

热点排行
Bad Request.