473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

New to CString. Why won't this compile?

I'm new to using CString. Why won't the following compile?
I'm using Microsoft Visual C++ 6.0

Line 37 which it complains about is the function:

37 CString ConvertFile(char *szFileName)

I tried throwing in a bunch of #includes but didn't help.
Here's the compiler errors:
Compiling...
UtoA.cpp
UtoA.cpp(37) : error C2146: syntax error :
missing ';' before identifier 'ConvertFile'
UtoA.cpp(37) : error C2501: 'CString' :
missing storage-class or type specifiers
UtoA.cpp(37) : fatal error C1004:
unexpected end of file found
Error executing cl.exe.

UtoA.exe - 3 error(s), 0 warning(s)

And here's the file UtoA.cpp I'm trying to compile:
(this code is from
http://www.codersource.net/win32_unicode_ascii.html)

#include "stdafx.h"
#include <cstring>
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
// http://www.codersource.net/win32_unicode_ascii.html

//Check if the file is UNICODE
int IsUnicodeFile(char* szFileName)
{
FILE *fpUnicode;
char l_szCharBuffer[80];

//Open the file
if((fpUnicode= fopen(szFileName,"r")) == NULL)
return 0; //Unable to open file

if(!feof(fpUnicode))
{
fread(l_szCharBuffer,80,1,fpUnicode);
fclose(fpUnicode);
if(IsTextUnicode(l_szCharBuffer,80,NULL))
{
return 2; //Text is Unicode
}
else
{
return 1; //Text is ASCII
}
}
return 0; // Some error happened
}

//Convert the file to ASCII type
CString ConvertFile(char *szFileName)
{
CString strTempFileName;
CString strInputFileName;
strInputFileName = szFileName;
char TempPathBuffer[260];
GetTempPath(260,TempPathBuffer);
FILE *fpASCII;
CStdioFileEx fpUnicode;

strTempFileName = TempPathBuffer;
strTempFileName += "TempUnicodecheck.txt";

if(IsUnicodeFile(szFileName) == 2)
{
//Open the UNICODE file
if(!fpUnicode.Open(szFileName,CFile::modeRead|CFil e::typeBinary))
{
printf("Unable to open the unicode file\n");
return strInputFileName ;
}

//Create the temporary file
if((fpASCII = fopen(strTempFileName.operator
LPCTSTR(),"w+"))==NULL)
{
fpUnicode.Close();
printf("Unable to open the output file\n");
return strInputFileName;
}

CString strData;
while(fpUnicode.ReadString(strData))
{
strData += "\n";
fwrite(strData,sizeof(char),strData.GetLength(),fp ASCII);
}
fflush(fpASCII);
fclose(fpASCII);
fpUnicode.Close();
return strTempFileName;
}
else
{
return strInputFileName;
}
}

int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
Dec 1 '06 #1
4 10468
Susan Rice wrote:
I'm new to using CString. Why won't the following compile?
I'm using Microsoft Visual C++ 6.0

Line 37 which it complains about is the function:

37 CString ConvertFile(char *szFileName)

I tried throwing in a bunch of #includes but didn't help.
Here's the compiler errors:
Compiling...
UtoA.cpp
UtoA.cpp(37) : error C2146: syntax error :
missing ';' before identifier 'ConvertFile'
UtoA.cpp(37) : error C2501: 'CString' :
missing storage-class or type specifiers
[..]

Most likely you have forgotten to include the very file that
defines that class. We do not know what it should be, CString
is not a standard class. Please ask in 'microsoft.public.vc.mfc'
for help.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 1 '06 #2
"Susan Rice" <sr****@cox.netwrote in message
news:Kx****************@newsfe10.phx
I'm new to using CString. Why won't the following compile?
I'm using Microsoft Visual C++ 6.0
Your question is Microsoft specific. You should ask in

microsoft.public.vc.language
Line 37 which it complains about is the function:

37 CString ConvertFile(char *szFileName)

I tried throwing in a bunch of #includes but didn't help.
Here's the compiler errors:
Compiling...
UtoA.cpp
UtoA.cpp(37) : error C2146: syntax error :
missing ';' before identifier 'ConvertFile'
UtoA.cpp(37) : error C2501: 'CString' :
missing storage-class or type specifiers
UtoA.cpp(37) : fatal error C1004:
unexpected end of file found
Error executing cl.exe.

UtoA.exe - 3 error(s), 0 warning(s)

And here's the file UtoA.cpp I'm trying to compile:
(this code is from
http://www.codersource.net/win32_unicode_ascii.html)

#include "stdafx.h"
#include <cstring>
cstring is the C++ version of the C standard library string header. It has
nothing to do with CString. CString was originally part of the MFC library
(and this is the case up to VC++ 6). From VC++ 7 onward, it was made
available independently of MFC.

Since you are using VC++6, you cannot use CString unless you are also using
MFC (unless you are going to hack the sources).

--
John Carson
Dec 1 '06 #3

Susan Rice wrote:
I'm new to using CString. Why won't the following compile?
I'm using Microsoft Visual C++ 6.0
poor you if you have to maintain some horrible MFC legacy code.
Line 37 which it complains about is the function:

37 CString ConvertFile(char *szFileName)
That declares a function that takes a writable pointer and returns a
CString. Now it's obvious to me that this function is not going to
modify szFileName so it should take const char * or that horrible
LPCSTR or LPCTSTR that Microsoft uses.
I tried throwing in a bunch of #includes but didn't help.
but not the right ones, presumably.
UtoA.exe - 3 error(s), 0 warning(s)

And here's the file UtoA.cpp I'm trying to compile:
(this code is from
http://www.codersource.net/win32_unicode_ascii.html)

#include "stdafx.h"
The one thing I hate most about VC even version 8 is being told by
default to include this file and getting some fatal error if I haven't.
I always disable precompiled headers as a result. I'd rather my code
took a bit longer to compile than it having to have this horrible
header in it.
#include <cstring>
This file does not contain CString but contains C string functions such
as strlen and strcpy defined in namespace std.
#include <windows.h>
I have a funny feeling that unless you include this one first it messes
everything up which goes against the principles of header files.
#include <string.h>
You have already included <cstring>. Even better would be to include
<stringand use std::string.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
If one does have to use these, then <cstdio<cctype(does that
exist?) and <cstdlib>

< snip some horrible C-style code that totally unnecessarily uses
CString >
>
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
At the end of all that your main ignores everything and prints "Hello
World!"

Dec 1 '06 #4

Earl Purple wrote:
<cctype(does that exist?)
Yes. <ctype.his in the C standard library.

std::tolower, std::toupper, std::isdigit etc.

Gavin Deane

Dec 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris | last post by:
Hi all, Just converted our 95 project workspace file from VC++ 6.0 to .NET, and things have gone...um...pretty well. Down to the last of the suffering - our main server application is doing...
9
by: Fausto Lopez | last post by:
I'm getting the following error: 'strlen' : cannot convert parameter 1 from 'class CString' to 'const char *' when I try to compile the following code: HRESULT AnsiToUnicode(CString pszA,...
5
by: Tim Wong | last post by:
All: I am trying to convert a CString value to an unsigned char array. I found some code online that will allow me to compile, but when I try to print out...i get a whole mess. /*Begin Code*/...
3
by: Javier | last post by:
Hi I'm newbie with C++/ADO and I'm (trying) to develop a littl app with VC++ 6 that connects with MSDE using ADO. At compile time I receive a lot of messages that say: 'CString' : undeclared...
0
by: Tony | last post by:
I have a managed C++ Console Application, and C++ Windows Forms application where I am trying to use an unmanaged header/lib file combo that exposes a class for functionality... The trouble I run...
8
by: Tony H | last post by:
Is there a way to read an MFC serialized class containing CStrings, ints, and doubles using a CLR-based class? Specifically, to get CString into System::String? Bye the Bye, is System:: String...
6
by: ATS | last post by:
INF: Has anyone made a CString, sprintf, and sscanf for .NET? Please help, I want to code with PURE .NET (i.e. pure CLR). No MFC, No ATL, no C-Run Time Library. But I want CString, sprintf,...
4
by: huguogang | last post by:
Just curious, any one know what the 3 part parameter "class CString filename" would mean. The code: int TestFunc(class CString filename) { fopen(filename, "w"); } Compile using Visaul C++,...
7
by: Old Wolf | last post by:
On one particular compiler, this program fails to compile because memset is an undeclared symbol (it's in namespace std but not in the global namespace): #include <cstring> #include <string.h>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.