0
#include <iostream>
#include <sstream>
using namespace std;
int main()
{

int a, b;
string s = "34:22";
istringstream ins;

ins.str(s);        
ins >> a >> b;    
cout <<a <<b;
}

This is my code and I want to ignore the ":" in string s. The outpout should be 3422. How can I do that?

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by pmark019
0

One way would be to go through the string and replace the ':' with a ' ' (either in a for loop, or through something like the .replace() method of the string.

Edit: Vijayan has a good way ^^^^^^^^^ (I was thinking along those lines but was trying other rhings, oh well).

Edited by jonsca: n/a

0

Thanks for your suggestions...I used vijayan's solution...How stupid of me not to think of it...:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.