c++ cli - Conversion from String to Char in visual c++ -


i taking input user in visual c++ through following code

console::writeline("select cache size.\n a. 1 kb \n b. 2 kb \n c. 4 kb \n d. 8 kb\n");     string^ cache_sizeoption = console::readline();     char wh= char(cache_sizeoption);      switch(wh)     {case 'a':     break;      case 'b':     break;      case 'c':      break;      case 'd':     break;     } 

in conversion string char giving errors..

 error c2440: '<function-style-cast>' : cannot convert 'system::string ^' 'wchar_t' 

it's unrealistic expect able convert string character. string can contain 0, 1 or more characters. character want?

if want first character, use cache_sizeoption[0], after having checked string not empty.

in case want add check string's length 1 because otherwise means user's input invalid. check cache_sizeoption->length.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -