[60分]2个简单问题!!

tudou614 2005-03-19 05:44:35
1.我有个string str= "this is just a test, and you will find some useful information";
如何通过定义的:char ch;把string中的字符
一个一个读入到ch中,
每次要做测试if(ch != ',')我要检测这个“,”号,想找个好点的办法!(有示范代码或函数最好)

2.三目运算符“(测试条件)? first :second ”要求first和second是同类型
如下:
假设我有一个数组:
要求输入的数值n>size时能输出"Error!",否则输出“总数”(total)
const int size = 10;
int array[] = {.........}; //小于10个
..........
int n;
cout<<"please input a int number n:"<<endl;
cin>>n;
.....
int total=0;
int temp = (n > size)? *(int*)ch:total; //这里不行

如下:
#include <iostream>
const int size = 10;
using namespace std;

int main()
{
int arr[] = {1, 2, 4, 8, 16, 32, 64, 128};

int n;
cout<<"Input the num of the arr[]: "<<endl;
cin>>n;
int total = 0;
if(n > size)
{
cout<<"error! Please input a correct number !"<<endl;

for(int i=0; i<n; i++)
{
total += arr[i];
}
cout<<"the address of the arr[]= "<<arr<<endl;
cout<<"the size of the arr[]= "<<sizeof arr<<endl;

char * ch ="error!";
char * temp = (n > size)? ch:(char *)total;

cout<<"the all number is: "<<temp<<endl;

}

cin.get();
return 0;
}
可以使用:while,do-while,for + if..else来写!!
...全文
183 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
kobefly 2005-03-19
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;

const int size = 10;

int main()
{
int arr[] = {1, 2, 4, 8, 16, 32, 64, 128};
int n;

cout<<"Input the num of the arr[]: "<<endl;
cin>>n;
int total = 0;
while(n > size)
{
cout<<"error! Please input a correct number !"<<endl;
cin >> n;
}
for(int i=0; i<n; i++)
{
total += arr[i];
}
cout<<"the address of the arr[]= "<<arr<<endl;
cout<<"the size of the arr[]= "<<sizeof (arr)<<endl;



cout<<"the all number is: "<<total<<endl;


cin.get();
return 0;
}
wolfkain 2005-03-19
  • 打赏
  • 举报
回复
char * temp = (n > size)? ch:(char *)total;有问题;total见定义(int total),所以
(char *)total出错,去掉(char *)会有temp=total,也错;写的什么狗屁!!!!!
tudou614 2005-03-19
  • 打赏
  • 举报
回复
第2个要求:可以使用while,do-while,for + if..else来写!!
就是如果数组越界了,能够输出字符串"Error",否则输出数组中元素的和,现在分开我都能实现
就是和在一起的时候强制转型搞不好
xxxdg 2005-03-19
  • 打赏
  • 举报
回复
char * temp = (n > size)? ch:(char *)total;

----------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>


char sTol[8];
sprintf(sTol,"%d",totoal);
char * temp =( n>size)?ch:sTol;


ltc_mouse 2005-03-19
  • 打赏
  • 举报
回复
char * temp = (n > size)? ch:(char *)total;
===================================================
total是一个数值,直接当作地址,是危险的,也得不到结果~
可以试试这个:
char strTotal[20];
sprintf(strTotal, "%d\0", total);
char *temp = (n>size) ? ch : strTotal;
kobefly 2005-03-19
  • 打赏
  • 举报
回复
第2个你说的似乎不太明白

我弄不懂
kobefly 2005-03-19
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{
string str= "this is just a test, and you will find some useful information";
const char *pch;
char ch;

pch = str.c_str();

while(ch = *pch)
{
if(ch == ',')
{
cout << "find!" << endl;
return 0;
}
pch++;
}

cout << "not find" << endl;

return 0;
}
ltc_mouse 2005-03-19
  • 打赏
  • 举报
回复
Sorry,看错了~
我还以为两个问题说明一样呢.........
ltc_mouse 2005-03-19
  • 打赏
  • 举报
回复
int temp = (n > size)? *(int*)ch:total; //这里不行
===========================================================
ch 是char类型的,能强制为int *吗? 改一下试试:
int temp = (n > size) ? (int)ch : total;
tudou614 2005-03-19
  • 打赏
  • 举报
回复
没人知道吗??
软件的核心功能:探测淘宝店铺宝贝是否被淘宝网隐形降权。 注意以下几个问题: 1、对于宝贝很多差不多上千宝贝的店铺 “降权宝贝”这个数据会出现问题,不用理会,这是淘宝的问题,淘宝的数据干扰! 2、不管什么情况下 隐形降权宝贝的数据是绝对正确的! 3、“隐形降权”这块出现负值,证明这个宝贝权重被降低了!正值的宝贝权重都没有问题,或者权重有加! 4、隐形降权的宝贝,也就是负值的宝贝目前宝贝排名肯定不在最前面! 被隐形降权的宝贝,不可能排到最前面,隐形降权这个问题是比较恶心的,可以通俗的这样说降权宝贝是指被直接枪毙的(但是可以去申诉,有机会成功),隐形降权宝贝是犯罪嫌疑人,处于观察阶段(无法申诉),从某种意义上讲,隐形降权比降权更难受! 隐形降权一般和以下因素有关: 1、刷销量:有黑号参与(被淘宝判断有刷销量嫌疑,但是不完全确定,就关小黑屋); 2、转化率低; 3、支付宝使用率。 简单的说,就是这个宝贝权重被扣了很多,要么想办法解决上面的因素,要么就是想办法给这个宝贝加,有些宝贝隐形降权恢复了,基本是有干净的正常的自然流量注入和自然的成交了一段时间然后恢复了,也就是说被淘宝释放了,所以怎么办?刷的要么你能保证刷号干干净净那么继续,要么就停止刷;转化率这块自己内功继续做足,有把握能用干干净将号刷的话,可以刷转化率出来;支付宝使用率这块很简单,不要经常改价和被退换货,这个自己把握。想给宝贝加要么搞转化率,要么搞老客户回头率,基本就这样,不能保证每个隐形降权宝贝都会回来! 软件评功能: 软件能根据查询店铺给予较合理的评,评数据参考店铺以及大淘宝整体20多项数据指标,满为百制,此数据可以体现店铺的整体经营成绩,如果低于60以下则需要认真检查店铺的经营状况进行调整。声明:此数据为整体参考数据,由商易论坛提供,并非淘宝官方数据,仅作为第三方参考,请勿用于商业用途,请知晓!

33,318

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧