473,387 Members | 1,844 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,387 software developers and data experts.

convert char to wchar

11
This is a test code to convert chat to wchar the problem is that each time the else statement is executed .....So the conversion is not working !!!!!!!



Expand|Select|Wrap|Line Numbers
  1. char p[500];
  2.  while(getline(inFile1, line))
  3.   {     
  4.     //we read p from file that contain only one word "why"............for testing
  5.     strcpy_s(p, 500, line.c_str());
  6.  
  7.     string search = p;
  8.     const size_t newsize = 100;
  9.     size_t origsize = strlen(search.c_str()) + 1;
  10.     size_t convertedChars = 0;
  11.     wchar_t wcstring[newsize];
  12.     mbstowcs( wcstring, search.c_str(), newsize);
  13.     wcscat_s(wcstring, L" (wchar_t *)");
  14.  
  15.     if(wcstring == L"why")
  16.             cout<<"Right conversion";
  17.             else
  18.             cout<<"Wrong conversion";
Oct 1 '10 #1
1 3246
weaknessforcats
9,208 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. if(wcstring == L"why")
This is always false.

wcstring is an array of wchar_t. Therefore, the name wcstring is the address of element 0. Ditto for L"why". That's the address of the "w".

Since there are two arrays the addresses will always be different.

I suggest you use wcscmp, or if you use the == operator, do so with two wstring objects.
Oct 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
7
by: MilanB | last post by:
Hello How to convert char to int? Thanks
2
by: Alper Akcayoz | last post by:
Hello Esteemed Developpers I would like to thank you in advance for your sincere responses I am a fresh Visual C++ .NET Developer. Can you kindly guide me for How to Convert char* to System::String
4
by: sweety | last post by:
Dear all, Kindy help to convert the char* ( LPCSTR) to WCHAR*(LPCWSTR). Would be great if you tell if any function does this job in VC++. Quick response will be greatfull...as its blocked... ...
1
by: Elioth | last post by:
Hi... I need to know how to convert Char Array to Byte Array and vice-versa in VB 2K5 Thanks for all help. Elioth
2
by: Joah Senegal | last post by:
Hello I need to convert a chat to a string... but I don't know how to do this. i;ve searched the internet but I've only find some code to convert char * to string or char to string.... but I...
3
by: simon | last post by:
I am a fresh Visual C++ .NET Developer. Can you kindly guide me for How to Convert char to System::String I am using windows forms and trying to set a text value referencing the method...
2
by: Rasheed | last post by:
Hi, i have a char pointer buffer which will hold the bitmap buffer, So i need to convert char *buffer as a bitmap. becuase when i draw on the Dialog using char *buffer. Nothing will be dispalyed....
1
by: helios | last post by:
Hi all, I'm resolved problem. and I want anybody need me that convert char to array bits char ConvertChar2ArrayBit(char ch) { char Bits; .... return Bits; } for...
3
by: mamul | last post by:
Hi please some one can help me. how to convert char * to string? i have take char *argv from command line and want to pass to a function as string object(string str) i want to first convert argv...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.