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

来源:互联网 发布:oppo手机的mac地址 编辑:程序博客网 时间:2024/05/21 17:35


练习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