問題タブ [string-view]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
3 に答える
11494 参照

c++ - std::string_view を int に安全に変換 (stoi や atoi など)

に変換する安全な標準的な方法はありますか?std::string_viewint


C++11では次のように変換std::stringできます:stoiint

ただしstoi、サポートしていませんstd::string_view。別の方法として、 を使用することもできますatoiが、次のように非常に注意する必要があります。

atoinullターミネータに基づいているため'\0'(たとえば、sv.substr単純に挿入/追加できないため)、どちらも機能しません。

現在、C++17 以降には もありますがfrom_chars、不十分な入力を提供するとスローされないようです: