How to print the first 3 characters of a string in C++

1 Answer

0 votes
#include <iostream>

int main() {
    std::string s = "c++ programming";
    std::string first_3 = s.substr(0, 3);

    std::cout << first_3;
}




/*
run:

c++

*/

 



answered Mar 3, 2021 by avibootz

Related questions

1 answer 161 views
1 answer 119 views
1 answer 131 views
1 answer 187 views
1 answer 129 views
1 answer 103 views
1 answer 131 views
...