string要用cin和cout输入和输出。

如果一定要用scanf和printf的话,格式为:

s.resize(20);scanf("%s", &s[0]);

printf("s=%s\n", s.c_str());

相关文章: