How to remove the last N characters from a string in C++

1 Answer

0 votes
#include <iostream>
#include <string>

int main() {
    std::string s = "c++ programming";
    const int N = 4;
    
    s = s.substr(0, s.length() - N);
    
    std::cout << s << std::endl;
}


/*
run:
       
c++ program
    
*/

 



answered Sep 12, 2024 by avibootz

Related questions

1 answer 106 views
1 answer 126 views
1 answer 94 views
1 answer 94 views
1 answer 136 views
...