#include <sstream>
using namespace std;
const char* GetHugeString();
int main()
{
const char* p = GetHugeString();
//
// Below will copy the huge string into a std::string object!
//
istringstream sstrm{p};
return {};
}
istringstream
不需要巨大字符串的副本;一个以null结尾的字符串指针就足够了。但是istringstream
的ctor
仅取std::string
,而不是std::string_view
(仅限于C++ 1z)作为它的参数。如何使istringstream更高效?
在这种情况下是否有解决方法使std::istringstream
更有效?
我不确定是否这是原因,但我怀疑这不被支持,因为内部存储是由'stringbuf'支持的,它不接受'string_view'(出于很好的理由)。 –