ncurses を使用して stdin からパスワードを読み取る必要がある Linux アプリを作成しています。問題なく C スタイルの文字列を読み取ることができますが、これはセキュリティ上のリスクをもたらすため、STL 文字列 (std::string) を読み取る方法を見つける必要があります。私のコードの関連部分は次のとおりです。
initscr();
noecho();
string key;
... // Get the key from the user
string enter=key+"A"; // So the entered key is not the user-set one
while(enter!=key)
{
const char* msg="Key to unlock terminal? ";
move(y/2, (x-strlen(msg))/2);
erase();
printw(msg);
sscanw("%s", enter); // How do I read into an STL string?
}