练习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;
}
- 练习3.6 for (auto &c;line) getline(cin,line ) 下标 有个程序有错误没改正
- getline(cin, line) demo
- 【C++】while(cin>>str); 和 getline(cin,line,'#');
- cin.get(line,ArSize) cin.getline(line,ArSize)和getline(cin,name)读取一行字符串区别
- 3.max points ona line(最多有多少个点在同一直线上)
- cin cin.get cin.getline有什么区别?(转载加部分原创)
- cin cin.get cin.getline有什么区…
- C++:cin、cin.getline()、getline()的用法
- C++:cin\cin.getline()\getline()的用法
- C++:cin\cin.getline()\getline()用法:
- 186.Max Points on a Line-最多有多少个点在一条直线上(中等题)
- cin、cin.get()、cin.getline()、getline()、gets()等函数的用法(C++)
- C 错误位置 FILE: C LINE: C
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法 学C++的时候,这几个输入函数弄的有点迷糊;这里做个小结,为了自己复习,也希望对后来者能有
- 【C++】cin、cin.get(char)和getline()
- [leetcode] Max Points on a Line 判断最多有多少个点在同一条直线上
- C - Line
- 算法6.6和6.7---有错误,未改正
- OpenGL蓝宝书源码学习(准备工作)
- GreenPlum 可读写外部表 实战
- UVALive
- c++第6次实验【项目4:字符删除】
- 公钥,私钥和数字签名这样最好理解
- 练习3.6 for (auto &c;line) getline(cin,line ) 下标 有个程序有错误没改正
- A3C代码详解
- linux 下载python psutil
- Elasticsearch java api(五) Bulk批量索引
- 随笔
- Python + OpenCV 实现简单的人脸识别
- jetty.io.EofException Broken pipe
- c++实验6-【项目3:矩阵求和】
- 猜数字游戏