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

1 Answer

0 votes
#include <iostream>

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

    std::cout << first_3;
}




/*
run:

c++ p

*/

 



answered Mar 3, 2021 by avibootz

Related questions

1 answer 100 views
1 answer 118 views
1 answer 116 views
1 answer 180 views
1 answer 178 views
1 answer 218 views
...