0

I am trying to convert char to wchar , but its not working !!the else case always executed in this code

char p[500];
 while(getline(inFile1, line))
  { 	
    //we read p from file that contain only one word "why"............for testing
    strcpy_s(p, 500, line.c_str());

    string search = p;
    const size_t newsize = 100;
    size_t origsize = strlen(search.c_str()) + 1;
    size_t convertedChars = 0;
    wchar_t wcstring[newsize];
    mbstowcs( wcstring, search.c_str(), newsize);
    wcscat_s(wcstring, L" (wchar_t *)");
    
    if(wcstring == L"why")
	        cout<<"Right conversion";
            else
	        cout<<"Wrong conversion";
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ekailan
0
char p[500] = nullptr
 while(getline(inFile1, line))
  { 	
    //we read p from file that contain only one word "why"............for testing
    strcpy_s(p, 500, line.c_str());

    string search = p;
    const size_t newsize = 100;
    size_t origsize = strlen(search.c_str()) + 1;
    size_t convertedChars = 0;
    wchar_t wcstring[newsize];
    mbstowcs( wcstring, search.c_str(), newsize);
    wcscat_s(wcstring, L" (wchar_t *)");
    
    if(wcstring == L"why")
	        cout<<"Right conversion";
            else
	        cout<<"Wrong conversion";
}

Edited by Orion2k: n/a

0

I did not get your point Do you mean that I should declare p like this

char p[500] = nullptr

ok its not working error nullptr not defined

and this is not working also

char *p;
      p = new char[500];
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.