输出操作符和getline读取string对象
2011-05-09 16:05
295 查看
#include <iostream>
#include <string>
using namespace std;
int main()
{
//getline读取string对象
//string line;
//while (getline(cin,line))
//{
// cout<<line<<endl;
// if (line=="exit")
// {
// break;
// }
//}
上述输出结果:
//输入操作符读取string对象 将空格符换行输出
string strLine;
while (cin>>strLine)
{
cout<<strLine<<endl;
if (strLine=="exit")
{
break;
}
}
上述输出结果:
system("pause");
}
#include <string>
using namespace std;
int main()
{
//getline读取string对象
//string line;
//while (getline(cin,line))
//{
// cout<<line<<endl;
// if (line=="exit")
// {
// break;
// }
//}
上述输出结果:
//输入操作符读取string对象 将空格符换行输出
string strLine;
while (cin>>strLine)
{
cout<<strLine<<endl;
if (strLine=="exit")
{
break;
}
}
上述输出结果:
system("pause");
}
相关文章推荐
- string代替char数组的输入输出以及利用getline每次读取一行字符串
- 编写一段程序,从标准输入读取string对象的序列直到连续出现两个相同的单词或者所有单词都读完为止。使用while循环一次读取一个单词,当一个单词连续出现两次是使用break语句终止循环。输出连续重复出现的单词,或者输出一个消息说明没有人任何单词是重复出现的。
- C++代码一次读取文本文件全部内容到string对象
- C++类中包含string类型数据使用read和write实现文件读取和输出时遇到的问题
- java输出string为对象,而不是值
- Json转string对象 打印输出; String 转json数组
- 读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。
- 编写一段程序,从标准输入读取string对象的序列直到连续出现两个相同的单词或者所有单词都读完为止
- C++使用getline读取string
- 读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。【轉】
- 使用web服务时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLen
- Python对象的文档字符串(DocString):__doc__的写法和输出方法
- 寻找string对象中的大写字母并输出
- java读取InputStream输入流后输出String字符串
- 设计一个学生类,其中包含学号、姓名、成绩等数据成员,创建学生对象并且倒入到文件file.txt,然后由文件读取到另一个学生对象并输出,试编程实现。
- C++,ifstream对象调用getline按行读取文本文件
- java读取InputStream输入流后输出String字符串
- leetcode412+vector赋值+非静态成员引用必须与特定对象相对+vector的输出+operator<<+to_string
- 使用Cout输出String和CString对象
- 【c/c++】C++代码一次读取文本文件全部内容到string对象