change const to variable string?

I have this from a reference code, and I figured it'd be useful and interesting if I could change the const char phrase to maybe a string that the user can enter, and it still complete the following function.
Is this possible?

1
2
3
4
5
6
7
8
9
  const char phrase[] = "Any text to be entered";

  std::cout << '"' << quote << "\"\n";

  // single character:
  std::cout << "begins with uppercase? : ";
  std::cout << std::boolalpha;
  std::cout << std::use_facet< std::ctype<char> >(loc).is (std::ctype<char>::upper, phrase[0]);
  std::cout << '\n';
1
2
char phrase[256];
cin.getline(phrase,sizeof(phrase));


But your code can work with C++ strings without any modifications too
1
2
3
string phrase;
   getline(cin,phrase);
// ... 
Last edited on
The first method worked, but I tried some alterations and couldn't get it to work as a string, since it is checking for the first character in the char type variable to see if it is upper.

But it's fine as is.

Thank you, Null.
Quote:
"couldn't get it to work as a string, since it is checking for the first character"


I don't see why that would be a problem.
phrase[0] will access the first character of a std::string just as well as for a plain character array.
Topic archived. No new replies allowed.