简体   繁体   English

CStdioFile未声明的标识符

[英]CStdioFile Undeclared Identifier

I am unable to compile my code when using a CStdioFile type. 使用CStdioFile类型时,我无法编译我的代码。 I have included the afx.h header file but I am still receiving errors. 我已经包含了afx.h头文件,但仍然收到错误。 What I am trying to do is write a cstring that contains an entire xml document to file. 我正在尝试做的是写一个包含整个xml文档的cstring文件。 This cstring contains comments inside of it, but when I use other objects such as wofstream to write it to file, these comments are striped out for some reason. 此cstring包含其中的注释,但是当我使用wofstream之类的其他对象将其写入文件时,由于某些原因,这些注释会被剥离。 So that is why I am trying to write this to file using CStdioFile now. 所以这就是为什么我现在尝试使用CStdioFile将其写入文件。 If anyone can help me out as to why I cannot compile my code using CStdioFile, or any other way to write a cstring that contains xml comments to file, please let me know! 如果有人可以帮助我解决为什么我不能使用CStdioFile或任何其他方式编写包含xml注释的cstring来编译代码的问题,请告诉我! Below is my code using CStdioFile: 下面是我使用CStdioFile的代码:

CStdioFile xmlFile;
xmlFile.Open( "c:\\test.txt", CFile::modeCreate | CFile::modeWrite | CFile::typeText );
xmlFile.WriteString( m_sData );
xmlFile.Close();

And my errors: error C2065: 'CStdioFile' : undeclared identifier error C2065: 'modeCreate' : undeclared identifier error C2065: 'modeWrite' : undeclared identifier error C2065: 'typeText' : undeclared identifier error C2065: 'xmlFile' : undeclared identifier error C2146: syntax error : missing ';' 我的错误:错误C2065:'CStdioFile':未声明的标识符错误C2065:'modeCreate':未声明的标识符错误C2065:'modeWrite':未声明的标识符错误C2065:'typeText':未声明的标识符错误C2065:'xmlFile':未声明的标识符错误C2146:语法错误:缺少';' before identifier 'xmlFile' error C2228: left of '.Close' must have class/struct/union type type is ''unknown-type'' error C2228: left of '.Open' must have class/struct/union type type is ''unknown-type'' error C2228: left of '.WriteString' must have class/struct/union type type is ''unknown-type'' error C2653: 'CFile' : is not a class or namespace name error C2653: 'CFile' : is not a class or namespace name error C2653: 'CFile' : is not a class or namespace name error C3861: 'xmlFile': identifier not found, even with argument-dependent lookup error C3861: 'xmlFile': identifier not found, even with argument-dependent lookup error C3861: 'xmlFile': identifier not found, even with argument-dependent lookup 标识符'xmlFile'之前的错误C2228:'.Close'的左侧必须具有类/结构/联合类型类型为'unknown-type'错误C2228:'.Open'的左侧必须具有类/结构/联合类型类型是``未知类型''错误C2228:'.WriteString'的左侧必须具有类/结构/联合类型类型为``未知类型''错误C2653:'CFile':不是类或名称空间名称错误C2653: 'CFile':不是类或名称空间名称错误C2653:'CFile':不是类或名称空间名称错误C3861:'xmlFile':找不到标识符,即使有依赖于参数的查找错误C3861:'xmlFile':标识符C3861:'xmlFile':即使使用参数相关的查找,也找不到标识符,即使使用参数相关的查找错误也未找到

Are you really including <afx.h> ? 您真的包括<afx.h>吗? Is it the right axf.h (you'd have to have something pretty odd going on on your system for it to not be)? 是正确的axf.h (您必须在系统上进行一些非常奇怪的操作才能使它不存在)? What compiler version are you using? 您正在使用哪个编译器版本?

This small program compiles and runs fine with VS2010 and VS2008: 这个小程序可以在VS2010和VS2008上编译并正常运行:

#include <afx.h>
#include <tchar.h>

int main()
{
    CStdioFile xmlFile;
    LPCTSTR m_sData = _T("Testing 123\n");

    xmlFile.Open( _T("c:\\temp\\test.txt"), CFile::modeCreate | CFile::modeWrite | CFile::typeText );
    xmlFile.WriteString( m_sData );
    xmlFile.Close();
}

What happens with it on your system? 在您的系统上会发生什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM