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 174 views
1 answer 207 views
1 answer 203 views
1 answer 275 views
1 answer 278 views
1 answer 306 views
...