我如何std :: getline()一个字符串? [英] How can I std::getline() a string?
本文介绍了我如何std :: getline()一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这个字符串
Let say I have this string
string myString = "This is a test string:value1/value2/value3/"
我如何做这样的事情:
How can I do something like this:
getline (myString, temp, '/');
我在想输出< myString
到文件,然后像往常一样使用
getline(output,temp,'/')
以其他方式。
谢谢,请帮助我。
I was thinking about output << myString
to a file, and then using
getline (output, temp, '/')
as usual, but I think there should be other ways.
Thanks, please help me.
推荐答案
getline
从流;因此您希望将字符串放入字符串流中:
getline
extracts from a stream; so you want to put your string into a string-stream:
#include <sstream>
std::stringstream ss(myString);
getline(ss, temp, '/');
这篇关于我如何std :: getline()一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文