How to remove specific character from a string by index in C++

1 Answer

0 votes
#include <iostream>

void removeCharAt(std::string &s, int pos) {
	s = s.substr(0, pos) + s.substr(pos + 1);
}

int main()
{
	std::string s = "C++ Programming";

	removeCharAt(s, 4);

	std::cout << s;
}




/*
run:

C++ rogramming

*/

 



answered Sep 20, 2022 by avibootz

Related questions

1 answer 278 views
1 answer 238 views
2 answers 340 views
1 answer 400 views
1 answer 278 views
1 answer 201 views
...