错误:

#include    <iostream.h>
#include    <string.h>

……

string    st("test    string");

……

error    C2065:    'string'    :    undeclared    identifier

解释:

#include    <string>

using    namespace    std;

因为在    using    namespace    std;    情况下,

#include    <string>      是使用    C++      string    类库;

#include    <cstring>      是使用    C    的string    操作库函数    ...

细节 加不加“.h”

#include <iostream.h>

#include <string>

using        namespace       std;

没有错!!

#include <iostream.h>

#include <string.h>

using        namespace       std;

编译有错!!

解释

“string.h“这个头文件是“旧式c头文件”,而这个文件中没有定义string类(这点应该不奇怪,c语言中哪有什么类啊),这个头文件里面是有关“旧式char-based字符串”的操作函数,注意都是操作char*字符串的“函数”,所以你引用这个头文件,编译器肯定找不到“string”了。   
   “string”这个头文件(没有扩展名)是C++标准化之后的C++头文件,里面才有string类的相关定义(其实,string并不是类,是一个typedef,但是使用的时候不用去管他),而C++标准头文件中的东西都放在namespace    std中了,所以使用的时候要“using    namespace    std”。   
   附:建议楼主不要用"iostream.h",改成“iostream”吧,因为标准已经明确规定不在支持"iostream.h"这种头文件了。

标准写法

#include <iostream>

#include <string>

using        namespace       std;

F: 为什么using    namespace    std;   
        要写在include后面?

Q: 因为include的文件包含名字域std   
如果你把using    namespace    std写在前面,编译器就看不到std这个名字

'string' : undeclared identifier相关推荐

  1. string : undeclared identifier 出错原因

    string : undeclared identifier 出错原因 在使用string类型时,添加了<string>头文件,编译后出现 'string' : undeclared id ...

  2. MFC工程 : view.h 包含错误, 提示 undeclared identifier 等错误

    比如已有:  testView.h testDoc.h resource.h  mynewfile.cpp 如果要在mynewfile.cpp中添加testView.h, 有时会提示 undeclar ...

  3. error:use of undeclared identifier

    HLS中error:use of undeclared identifier 问题描述 在编写HLS代码过程中,使用流数据时报错,说我的标识符未声明.但是分明是定义了的,HLS编译器不认识. 错误位置 ...

  4. error C2065: 'assert' : undeclared identifier

    F:\VC6.0 : error C2065: 'assert' : undeclared identifier 导入#include <assert.h> 转载于:https://www ...

  5. c2061 dword 语法错误_解决'PMIB_ICMP_EX':undeclared identifier

    FreeEIM 飞鸽传书编译问题总结,最近对FreeEIM 进行了更新,结果编译的时候出现了许多错误,是什么导致这些错误呢?我花了半天时间才得以解决,现在总结一下. ----------------- ...

  6. c语言 'max' : undeclared identifier,c语言中undeclared identifier是什么意思?

    在c语言中,"undeclared identifier"的意思是"未声明的标识符":一般是使用的变量或者函数没有定义,或者是定义的时候和调用的时候不一致导致的 ...

  7. c语言编译kbhit出现问题,在VC++中运行出现error C2065: 'kbhit' : undeclared identifier,什么意思?怎么调试?...

    在VC++中运行出现error C2065: 'kbhit' : undeclared identifier,什么意思?怎么调试?0 yareate2013.04.08浏览493次分享举报 #defi ...

  8. [Android]Android studio编译程序时报错: error: use of undeclared identifier ’free free(t);

    原文地址:https://blog.csdn.net/u010005281/article/details/78611389 问题描述:程序之前可以正常运行,后来更新了一系列部件之后编译不通过,报了好 ...

  9. Error C2065 'cout': undeclared identifier

    1 [问题背景]C++/MFC中出现 Error    C2065错误,即未定义xxx错误,而你使用的xxx是基础类库的,你心里想不可能不存在呀.当然排除你拼写错误的情况,咱不讨论这种情况. 2 [分 ...

最新文章

  1. 面向对象软件设计的“开—闭”原则
  2. JZOJ 5424. 【NOIP2017提高A组集训10.25】凤凰院凶真
  3. Linux - 简单设置 vim (tab, 行号, 换行)
  4. 程序员拯救乐坛?OpenAI 用“逆天”GPT2.0 搞了个 AI 音乐生成器
  5. 有哪些好用的低代码开发平台?
  6. 用Android studio搭建沃商店SDK任意支付的配置
  7. 倍福---绝对值编码器位置保存
  8. 基于C++的菜鸟驿站
  9. python识别手写数字knn_手写数字识别以及Python sklearn KNN实现
  10. 全国各地网站备案的通过时间表
  11. linux学校_济南教师招聘 |济南市益友培训学校7大岗位教师招聘(月薪4k15k、包住)...
  12. 如何扩展关键词,以及使用python多线程爬取bing搜索结果
  13. 房租客手机端个人中心html页面
  14. 解读PureMVC框架
  15. apex英雄哪个服务器稳定,apex英雄哪个服务器好
  16. flask使用Blueprint
  17. iOS微信聊天界面朋友圈多个小视频同时播放不卡顿
  18. 观复嘟嘟:职场是个技术活-马未都
  19. 符合w3c 的 strict标准,用 rel 替换_blank打开新窗口
  20. 基于cmake配置使用CGAL

热门文章

  1. sql server2016连接失败
  2. 制作wordpress留言板
  3. Tiled地图编辑器(一)实现坦克大战
  4. 硬盘存储FC光纤连接服务器显示脱机解决方法
  5. Gartner2019年十大安全项目详解
  6. 毕业设计----多功能电子词典的设计与实现效果展示
  7. 绿色无捆绑大白菜U盘启动盘制作
  8. 摄像头录像大师推荐?如何录制摄像头,图文教程
  9. Java 定时任务详解
  10. 大数据实时处理半期总结报告