string用scanf读入printf输出(节省时间)

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
    string a;
    a.resize(100); //需要预先分配空间
    scanf("%s", &a[0]);
    printf("%s\n", a.c_str());
    return 0;
}

 

posted @ 2018-12-02 20:31  莫莫君不恋爱  阅读(383)  评论(0编辑  收藏  举报