'string' : undeclared identifier
错误:
#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相关推荐
- string : undeclared identifier 出错原因
string : undeclared identifier 出错原因 在使用string类型时,添加了<string>头文件,编译后出现 'string' : undeclared id ...
- MFC工程 : view.h 包含错误, 提示 undeclared identifier 等错误
比如已有: testView.h testDoc.h resource.h mynewfile.cpp 如果要在mynewfile.cpp中添加testView.h, 有时会提示 undeclar ...
- error:use of undeclared identifier
HLS中error:use of undeclared identifier 问题描述 在编写HLS代码过程中,使用流数据时报错,说我的标识符未声明.但是分明是定义了的,HLS编译器不认识. 错误位置 ...
- error C2065: 'assert' : undeclared identifier
F:\VC6.0 : error C2065: 'assert' : undeclared identifier 导入#include <assert.h> 转载于:https://www ...
- c2061 dword 语法错误_解决'PMIB_ICMP_EX':undeclared identifier
FreeEIM 飞鸽传书编译问题总结,最近对FreeEIM 进行了更新,结果编译的时候出现了许多错误,是什么导致这些错误呢?我花了半天时间才得以解决,现在总结一下. ----------------- ...
- c语言 'max' : undeclared identifier,c语言中undeclared identifier是什么意思?
在c语言中,"undeclared identifier"的意思是"未声明的标识符":一般是使用的变量或者函数没有定义,或者是定义的时候和调用的时候不一致导致的 ...
- c语言编译kbhit出现问题,在VC++中运行出现error C2065: 'kbhit' : undeclared identifier,什么意思?怎么调试?...
在VC++中运行出现error C2065: 'kbhit' : undeclared identifier,什么意思?怎么调试?0 yareate2013.04.08浏览493次分享举报 #defi ...
- [Android]Android studio编译程序时报错: error: use of undeclared identifier ’free free(t);
原文地址:https://blog.csdn.net/u010005281/article/details/78611389 问题描述:程序之前可以正常运行,后来更新了一系列部件之后编译不通过,报了好 ...
- Error C2065 'cout': undeclared identifier
1 [问题背景]C++/MFC中出现 Error C2065错误,即未定义xxx错误,而你使用的xxx是基础类库的,你心里想不可能不存在呀.当然排除你拼写错误的情况,咱不讨论这种情况. 2 [分 ...
最新文章
- 面向对象软件设计的“开—闭”原则
- JZOJ 5424. 【NOIP2017提高A组集训10.25】凤凰院凶真
- Linux - 简单设置 vim (tab, 行号, 换行)
- 程序员拯救乐坛?OpenAI 用“逆天”GPT2.0 搞了个 AI 音乐生成器
- 有哪些好用的低代码开发平台?
- 用Android studio搭建沃商店SDK任意支付的配置
- 倍福---绝对值编码器位置保存
- 基于C++的菜鸟驿站
- python识别手写数字knn_手写数字识别以及Python sklearn KNN实现
- 全国各地网站备案的通过时间表
- linux学校_济南教师招聘 |济南市益友培训学校7大岗位教师招聘(月薪4k15k、包住)...
- 如何扩展关键词,以及使用python多线程爬取bing搜索结果
- 房租客手机端个人中心html页面
- 解读PureMVC框架
- apex英雄哪个服务器稳定,apex英雄哪个服务器好
- flask使用Blueprint
- iOS微信聊天界面朋友圈多个小视频同时播放不卡顿
- 观复嘟嘟:职场是个技术活-马未都
- 符合w3c 的 strict标准,用 rel 替换_blank打开新窗口
- 基于cmake配置使用CGAL