输出奇数位的字符

来源:互联网 发布:ipad air2实用软件 编辑:程序博客网 时间:2024/06/08 06:46
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
int i, j, count = 0;
cin >> str;
for (i = 0; str[i] !='\0'; i++)//一串字符最后一位是'\0'
count++;//计算字符串的长度
for (j = 0; j <= count; j++)
{
if (j % 2 != 0)//j%2!=0时是偶数位的字符
cout << str[j - 1];//输出奇数位字符
}
system("pause");
return 0;
}
0 0
原创粉丝点击