练习3.6 for (auto &c;line) getline(cin,line ) 下标 有个程序有错误没改正


练习3.6   for (auto &c;line)   getline(cin,line)

   

#include "stdafx.h"

#include<iostream>
#include<string>
using namespace std;
int main()
{
string line;
cout << "input:" << endl;
//cin >> line;因为字符包含空格,所以输入应该用getline
getline(cin, line);
for (auto &c : line)//要改变所以用引用,注意是:冒号,auto要会用
c = 'X';
cout << line << endl;
system("pause");
    return 0;

}



#include<cctype>//千万莫忘!!

#include "stdafx.h"
#include<iostream>
#include<string>
#include<cctype>//千万莫忘!!
using namespace std;
int main()
{
//3.6
/*
string line;
cout << "input:" << endl;
//cin >> line;因为字符包含空格,所以输入应该用getline
getline(cin, line);
for (auto &c : line)//要改变所以用引用,注意是:冒号,auto要会用
c = 'X';
cout << line << endl;
*/


//3.10 将标点符号去掉后 输出字符串的剩余部分


/*string line;
cout << "input:" << endl;
decltype(line.size())n = line.size();
getline(cin, line);
for (decltype(line.size()) index=0;index<line.size();++index)
{
if (ispunct(line[index]))
{
for (index=0; index < line.size() - 1; ++index)
{
line[index] = line[index + 1];
n = line.size() - 1;
}
}
}
for (decltype(line.size()) index = 0; index < n; ++index)
cout << line[index];
//下标向前移太麻烦  完全可以弄个新串   法一:不是符号就输出   法二:用下标   加起来  result=srsult+s[i]
/*???????????????????有错没改    ??????????????


/*
//对于调试时出的错误,可以新建个工程 重试
string line;
cout << "input:" << endl;
getline(cin, line);//含空格 用getline
for (auto c : line)//不改变不用&
{
if (!ispunct(c))//不是就输出
cout << c;
}
cout << endl;
*/
system("pause");
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值