标题:能帮我看看这个问题吗?动态结构数组内字符数组成员赋值问题。。详情见内。 ...
取消只看楼主
WizCas
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-10-22
 问题点数:0 回复次数:0 
能帮我看看这个问题吗?动态结构数组内字符数组成员赋值问题。。详情见内。。

//ex6.cpp The exercise 6 in 6.10 of C++ Primer Plus //2005-10-24, WizCas #include <iostream> #include <cctype> using namespace std; const int ArSize = 20;

struct person { char name[ArSize]; double money; };

int main() { cout << "Enter the number of the patron: "; int n; cin >> n; cin.get(); person *payer = new person [n]; int i; cout << "Enter the name and the amount for each patron: \n"; for (i = 0; i < n; i++) { cout << "Patron #" << i + 1 << endl; cout << "Name: "; cin.get(payer[i].name, ArSize).get(); if (payer[i].name == " " || payer[i].name == "\n") payer[i].name = "none"; cout << "Amount: "; cin >> payer[i].money; cin.get(); cout << "\n"; } cout << "Here is the namelist of the patrons: \n" "==Grand Patrons==\n"; for (i = 0; i < n; i++) if (payer[i].money > 10000) cout << payer[i].name << " " << payer[i].money << endl; cout << "==Patrons==\n"; for (i = 0; i < n; i++) if (payer[i].money <= 10000) cout << payer[i].name << " " << payer[i].money << endl; system ("pause"); return 0; }

到 payer[i].name = "none"; 这一行就不行了,用Dev C++编译,显示错误 incompatible types in assignment of 'const char[5]' to 'char[20]'

请问这是怎么回事?还有这句 if (payer[i].name == " " || payer[i].name == "\n") 我的本意是当payer[i].name的值为空,这样写是不是麻烦了?有没有什么更好的解决办法?我试了 if (isspace(payer[i].name)) 可是报告错误invaild convertion from 'char*' to 'int'和 initializing argument 1 of 'int isspace(int)' 请各位帮我解决一下!谢谢!!!

[此贴子已经被作者于2005-10-24 19:07:43编辑过]

搜索更多相关主题的帖子: 数组 赋值 动态 详情 字符 
2005-10-24 18:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-31253-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.205961 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved