Zac*_*low 3 c++ printf declaration
我在编译此代码时收到此错误字符串未声明.
#include <stdio.h>
#include <stdlib.h>
int main()
{
string names;
printf("What is your name?\n");
scanf("%s", &names);
printf("Your name is %s", names);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我为什么.非常感谢
你应该包括字符串标题:
#include <string>
Run Code Online (Sandbox Code Playgroud)
并且std在使用它时不要忘记命名空间:
std::string names;
Run Code Online (Sandbox Code Playgroud)
此外,编码时不要混用C和C++.尝试使用std::cout不printf,cin/getline不scanf.
| 归档时间: |
|
| 查看次数: |
70 次 |
| 最近记录: |