#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?

Recommended Answers

All 3 Replies

int main()
{
    int a, b;
    char c ;

    // ...

    ins >> a >> c >> b;    
    cout <<a <<b;
}

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).

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.