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.
char配列をstd::stringに変換する方法を見つけようとしていますが、これを行う方法が見つかりません。
それが不可能な場合は、std::string を読み取る方法を説明していただけますか? しかし、scanf()とgets()では読み取れません。
よろしくお願いします。
文字配列から文字列を作成する最も簡単な方法は、次のようにポインターと長さを取るコンストラクターを使用することです。
char charArray[] = {'w', 'x', 'y', 'z'}; std:string s(&charArray[1], 2); // s is "xy" // ^ ^ // | | // Pointer to the | // starting position Length