C + +: stripping '/' char from IStream [input stream] [quot]
Q: In C ++. What is the easiest way to strip a “slash” from an input stream so I can just work with whats left?
Stream Online Tv – Top Converting!
Re:Depends on what kind of string you are using. The old string or the STL string.
Once you learn the STL strings they are a lot more flexible and easier to do stuff like this with.
#include <string>
using namespace std;
string dir = "/usr/local/bin";
for (string::iterator s = dir.begin(); s != dir.end(); ) {
if (s == '/')
s.erase();
else
++s;
}
I'm about 95% sure that's the way I did it. My source is at the office so if that doesn't work for you I'll doublecheck.
EDIT: Sorry I thought you said string instead of stream. ![]()
Quotes Of Inspiration
Re:How about simply initializing a temporary buffer, then use a for loop to go through each character in the stream. If not slash character, put it in temp buffer and increment buffer length, else ignore. At the end, null-terminate the buffer.
Crude, but works.
atwl
Stream Online Movies – Top Tv Product
Re:http://www.cppreference.com/cppstring.html should help
I don't know of a better way than doing find('/', 0) w/ replace(index, 1, '') in a loop until find returns npos.
Auction Profit Streams
Re:Yea that's exactly what I need to do
Auction Profit Streams
Re:I guess you mean pull them all out and replace with nothing?
So you take /usr/blah/blah and convert it to usrblahblah before working with it?
Related posts
Tags: input stream, quot