+ 1

How can I access sa particular letter in string?

Suppose I take input of a string and want to print only its first letter. How can I do that?

16th Oct 2020, 2:06 AM
Ved Thaker
Ved Thaker - avatar
4 Antworten
+ 1
#include <iostream> #include <string> int main(int argc, char *argv[]) { std::string input; std::getline(std::cin,input); std::cout<<input[0]; } //here 0 is the index of first character
16th Oct 2020, 5:00 AM
Aditya rout
Aditya rout - avatar
+ 3
Aditya rout and Ipang thanks for helping me understand
17th Oct 2020, 2:41 AM
Ved Thaker
Ved Thaker - avatar
+ 2
Various ways to obtain first character in a basic string. (Edit) Naam Mein Kya Rakha Hai 😉 Next time please include language specifics earliest in the tags, just to avoid misunderstanding : ) https://code.sololearn.com/cpxpf97RkL1F/?ref=app
16th Oct 2020, 2:44 AM
Ipang
+ 1
BroFar Sir, my DM still doesn't work. I have noted the OP by edits though ...
16th Oct 2020, 2:52 AM
Ipang