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 @ 2019-02-16 10:21  erge1998  阅读(1585)  评论(0编辑  收藏  举报