加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 编译代码时出错

发布时间:2020-12-16 10:33:52 所属栏目:百科 来源:网络整理
导读:我在编译此代码时收到此错误字符串未声明. #include stdio.h#include stdlib.hint main(){string names;printf("What is your name?n");scanf("%s",names);printf("Your name is %s",names);return 0;} 有人可以告诉我为什么.非常感谢 解决方法 你应该包括
我在编译此代码时收到此错误字符串未声明.

#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;
}

有人可以告诉我为什么.非常感谢

解决方法

你应该包括字符串标题:

#include <string>

并且在使用它时不要忘记命名空间std:

std::string names;

此外,编码时不要混用C和C.尝试使用std :: cout而不是printf,cin / getline不是scanf.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读