[60分]2个简单问题!!
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来写!!
如何通过定义的: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来写!!
...全文
相关推荐
STC12C5A60S2简单的AD转换程序
很简单的A/D转换程序,转化结果精确到小数点后两位,包含1602驱动程序。
STC12C5A60S2 51单片机简单示波器
STC12C5A60S2单片机内部AD采样;LCD12864显示波形;LM393组成迟滞比较器测量小信号频率,不需要频率显示时该部分可以省略。
编程序实现设有10个学生的成绩分别为85、62、64、79、82、99、100、78、88、86,试编制一个子程序统计60~69分,70~79分 ,80~89分,90~99分及100分的人数,分别存放到S6,S7,S8,S9及S10单元中。
编程序实现设有10个学生的成绩分别为85、62、64、79、82、99、100、78、88、86,试编制一个子程序统计60~69分,70~79分 ,80~89分,90~99分及100分的人数,分别存放到S6,S7,S8,S9及S10单元中。
bilibili60分问题答案汇总.doc
bilibili60分问题答案汇总.doc
c代码-输入某学生的成绩,经处理后给出学生的等级,等级分类如下: 90分以上(包括90): A 80至90分(包括80):B 70至80分(包括70):C 60至70分(包括60):D 60分以下:E
c代码-输入某学生的成绩,经处理后给出学生的等级,等级分类如下: 90分以上(包括90): A 80至90分(包括80):B 70至80分(包括70):C 60至70分(包括60):D 60分以下:E


新手乐园
