Learn how to Make Money Online doing freelancing, Affiliate Marketing, Blogging and many more ...
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Queries and Discussion > Programming > MFC / Win32

Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Thread Tools Search this Thread Display Modes
Old 12-28-2009, 11:35 AM   #1
Ambitious contributor
 
Join Date: Dec 2007
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 3
answerme is on a distinguished road

Converting error from 'CString' to 'const char *


Hi I am getting a conversion error

Code:
CString Instring;
CString Automesg[2];
Automesg[0]="test 1";
Automesg[1]="Test Example2";
if(strcmp(Instring,Automesg[0])==0) //HERE IS THE ERROR FOR InString Variable
	{
		Sleep(1000);
         }

error C2664: 'strcmp' : cannot convert parameter 1 from 'CString' to 'const char *'	
Can anyone resolve it
answerme is offline   Reply With Quote
Old 12-28-2009, 04:48 PM   #2
~ Б0ЯИ Τ0 С0δЭ ~
 
SaswatPadhi's Avatar
 
Join Date: May 2009
Location: Orissa, INDIA
Posts: 1,344
Thanks: 47
Thanked 79 Times in 57 Posts
Rep Power: 5
SaswatPadhi is a jewel in the roughSaswatPadhi is a jewel in the roughSaswatPadhi is a jewel in the rough

Re: Converting error from 'CString' to 'const char *


You can use the "compare" function.

Say, you have 2 CStrings StringA and StringB.
You can compare them like :
Code: CPP
if ( StringA.compare(StringB) == 0 ) cout << StringA << " and " << StringB << " are not equal.";

So, your code can be modified as :
Code: CPP
CString Instring;
CString Automesg[2];
Automesg[0]="test 1";
Automesg[1]="Test Example2";
if(Instring.compare(Automesg[0])==0)
{      Sleep(1000);   }
SaswatPadhi is offline   Reply With Quote
Old 12-28-2009, 06:35 PM   #3
Contributor
 
Join Date: Nov 2009
Posts: 93
Thanks: 0
Thanked 4 Times in 4 Posts
Rep Power: 1
Gene Poole will become famous soon enough

Re: Converting error from 'CString' to 'const char *


I think the problem is likely a UNICODE issue. With UNICODE enabled in your project, CStrings default to "wide" character strings. A "wide" character is 2 bytes whereas normal char is 1 byte. You can use the "wide" versions of the comparison functions, wcscmp() v. strcmp(), or to keep everything portable, use the TCHAR macros. _tcscmp() is a macro that will evaluate to strcmp() in MCBS builds or wcscmp() in UNICODE builds.
Gene Poole is offline   Reply With Quote
Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads / Articles
Thread Thread Starter Forum Replies Last Post
Sudoku Solving Program Using 'C' rai_gandalf Game programming 48 04-15-2010 08:10 PM
simple implementation of FTP on "C" tonio C-C++ 3 11-03-2008 11:19 PM
converting binary tree into linear hashing code viewsonic C-C++ 0 04-24-2008 03:10 AM
The use of the code analysis library OpenC++: modifications, improvements, error fixs Karpov2007 C-C++ 4 03-05-2008 08:42 AM
Sudoku Class tailhook123 C-C++ 1 05-30-2007 10:43 PM

 

All times are GMT +5.5. The time now is 05:34 AM.