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
...