C++ :为什么new char[100]分配的数组不能用scanf(%s)输入
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char*argv[])
{
char *str = new char[1000];
scanf("%s", &str);
printf("%s\n",str);
return 0;
}
char *str = new char[1000];
scanf("%s", &str);
输入的时候不用加&取地址运算符,因为str本身就是一个地址;去掉取地址&运算符就可以了楼主。
#include <iostream>
using namespace std;
c++语言得加上面这两个