#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'(出於很好的理由)。 –