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 193 views
1 answer 224 views
1 answer 182 views
1 answer 193 views
1 answer 221 views
1 answer 187 views
...