且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过引用传递子字符串?

更新时间:2023-11-14 13:01:40

您不能使用 std :: string 为此,但是您可以轻松地创建自己的类,该类将一对迭代器(开始和结束)保存到另一个字符串或C样式的char *中。和大小。使用C ++ 11(因为已经对其进行了标记),您甚至应该能够使用用户定义的文字语法来创建新类型的字符串。

You cannot use std::string for this purpose, but you can easily make a class of your own that holds a pair of iterators (begin and end) into another string, or a C-style char* and size. With C++11 (since you tagged it), you should even be able to make a User Defined Literal syntax for creating strings of your new type.