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 176 views
2 answers 216 views
1 answer 145 views
1 answer 99 views
1 answer 265 views
...