Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我在 C++ 中有一个字符串,我想对它做不同的操作,比如:
搜索字符序列,将文本块转换为 int(在行的中间),来回移动 get 指针等等。
用字符串流做这种事情的标准/常用方法是什么?
您可以使用返回关联的 std::string 对象的 stringstream::str() 方法。然后您可以对返回的字符串执行所需的操作。
顾名思义,stringtream 是一个流。流允许顺序访问,而不是随机访问。如果要随机访问,可以使用 stringstream::str() 函数来获取字符串的字符串版本。