CStdioFile Undeclared Identifier

4.1k views Asked by At

I am unable to compile my code when using a CStdioFile type. I have included the afx.h header file but I am still receiving errors. What I am trying to do is write a cstring that contains an entire xml document to file. 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. So that is why I am trying to write this to file using CStdioFile now. 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! Below is my code using 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 ';' 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

1

There are 1 answers

0
Michael Burr On

Are you really including <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)? What compiler version are you using?

This small program compiles and runs fine with VS2010 and 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?