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
Post a Comment