hhaoma 2008-6-11 16:07
c++帮忙看看修改动态增加数组
下面那段代码只能输入和输出数字~~~帮忙改下如何让它输入中文和输出英文~~
[code]
#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!";
}
}
}
[/code]
Administrator 2008-6-11 18:59
你的控制台环境要支持中文才行
hhaoma 2008-6-11 19:41
帮忙改下面的~~输入中文和输出中文
#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[i]<<endl;
}
break;
case'q':
return;
default:
cout<<"\n Your enter is error,select again!";
break;
}
}
}
Weight::~Weight()
{
delete []weight;
}
void main()
{
Weight w;
}
大道至简 2008-6-11 20:54
[url]http://www.vckbase.com/document/viewdoc/?id=1082[/url]
whislter 2008-6-18 11:19
用string,vector不就好了
console下打开、关闭中文输入法是Ctrl+Space
whislter 2008-6-26 11:22
用string输入输出中文肯定行,我试过
我怀疑是VC6对STL的支持有问题,找个其他编译器试试,VC6可以说是最最背离标准的一个编译器了
再不行的话,你把改完后的代码发上来我看看
还有就是我觉得你直接用字符数组输入输出中文也是可以的,处理控制台的显示是操作系统的事,跟C++没关系,区别只在于你用的是不是unicode,但是已经说了,处理编码是控制台的事,你用MBCS和UNICODE最终得到的中文字符内码是一样的(中文系统),这些我都验证过了
lonely00 2008-6-26 13:37
回复 6# 的帖子
default后面的break不需要吧,否则怎么再选哦