注册 登录
编程论坛 C++教室

字符串变量使用 但是系统一直提示没有 声明字符串类

愿o圆o安 发布于 2017-04-06 00:04, 1933 次点击
#include<iostream.h>
#include<string>

class str
{
private:
    string zfc[5];
public:
    void input();
    void compare();
    void print();
};

void str::input()
{
    cout<<"please enter:"<<endl;
    for(int i=0;i<5;i++)
        cin>>zfc[i];
}

void str::compare()
{
    string step;
    for(int i=0;i<4;i++)
        for(int j=i;j<4-i;j++)
        {
            if(zfc[j]<zfc[j+1])
            {
                step=zfc[j];
                zfc[j]=zfc[j+1];
                zfc[j+1]=step;
            }
        }
}

void str::print()
{
    for(int i=0;i<5;i++)
        cout<<zfc[i]<<endl;
}

void main()
{
    str country;
    country.input();
    ();
    country.print();
}
1 回复
#2
rjsp2017-04-06 08:19
#include <iostream>
#include <string>
using namespace std;
1