14 12
发新话题
打印

c++帮忙看看修改动态增加数组

c++帮忙看看修改动态增加数组

下面那段代码只能输入和输出数字~~~帮忙改下如何让它输入中文和输出英文~~
复制内容到剪贴板
代码:

#include <iostream.h>
#include <stdlib.h>
#define Min 0
void main()
{
int total=0;
float * weight;
weight=new float[Min];
int i;
for(i=0;i<Min;i++)
{
  weight[i]=0.0;
}
char c;
while(true)
{
  cout<<"\n* * * * * * * * * * * * * * * * * * * * * * * * * *";
  cout<<"\n a: 输入数据;";
  cout<<"\n t:显示所有;";
  cout<<"\n q:退出;";
        cout<<"\n* * * * * * * * * * * * * * * * * * * * * * * * * *";
  cout<<"\n 请选择:";
  cin>>c;
  switch(c)
  {
  case'a':
   if(total>=Min)
   {
    weight=(float * )realloc(weight,(total+1)*sizeof(float));
   }
   cout<<"Enter the"<<total<<"cargo's weight,please:";
   cin>>weight[total];
   total++;
   break;
  case't':
   for(i=0;i<total;i++)
   {
    cout<<"The"<<i<<" weight is:"<<weight[i]<<endl;
   }
   break;
  case'q':
   delete[]weight;
   return;
  default:
   cout<<"\n Your enter is error,select again!";
  }
}
}

TOP

错了

是让它能输入中文和输出中文

TOP

你的控制台环境要支持中文才行

TOP

会c++的来

TOP

呵呵

我用的是vc++ 6.0
应该支持中文吧~

TOP

帮忙改下面的~~输入中文和输出中文

#include <iostream.h>
#include <stdlib.h>
#define Min 0
class Weight
{
private:
    float *weight;
    int total;
public:
    Weight();
    ~Weight();
};

Weight::Weight()
{
    weight=new float[Min];
    total = 0;
    int i = 0;
    char c=0;

    while(true)
    {
        cout<<"\n* * * * * * * * ";
        cout<<"\n 1: 输入数据;";
        cout<<"\n 2: 显示所有;";
        cout<<"\n q: 退出;";
        cout<<"\n* * * * * * * * ";
        cout<<"\n请选择:";
        cin>>c;
        switch(c)
        {
        case'1':
            weight=(float * )realloc(weight,(total+1)*sizeof(float));
            cout<<"Enter the "<<total<<" cargo's weight,please:";
            cin>>weight[total];
            total++;
            break;
        case'2':
            for(i=0;i<total;i++)
            {
                cout<<"The "<<i<<" weight is: "<<weight<<endl;
            }
            break;
        case'q':
            return;
        default:
            cout<<"\n Your enter is error,select again!";
            break;
        }
    }
}

Weight::~Weight()
{
    delete []weight;
}

void main()
{
    Weight w;
}

TOP

因为梦想而努力,因为有你而精彩!
mail: qianzongming@gmail.com

TOP

能写得出来吗??

TOP

没试过。
因为梦想而努力,因为有你而精彩!
mail: qianzongming@gmail.com

TOP

用string,vector不就好了
console下打开、关闭中文输入法是Ctrl+Space

TOP

 14 12
发新话题