xxxxxxxxxx
string car = "audi";
char firstCharacter= car.at(0);
cout<< firstCharacter;
xxxxxxxxxx
#include <iostream>
#include <string>
int main()
{
string str{}; // creating string
getline(cin, str);// using getline for user input
std::cout << str; // output string namePerson
if (str[0] >= 'a' || str[0] <= 'z')
str[0] -= 32;
return (0);
}
xxxxxxxxxx
// string::at
#include <iostream>
#include <string>
int main ()
{
std::string str ("Test string");
for (unsigned i=0; i<str.length(); ++i)
{
std::cout << str.at(i);
}
return 0;
}
xxxxxxxxxx
std::string input = word;
std::string firstWord = input.substr(0, input.find(" "));
cout << " The word is: " << firstWord << endl;
cout << endl;