Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <string.h>
- using namespace std;
- class StringParser
- {
- private:
- int pos;
- char *input_str;
- char *delimiters;
- public:
- StringParser(char *inp, char *delim)
- {input_str = inp;delimiters = delim;pos = 0;}
- StringParser(char *delim)
- {delimiters = delim;pos = 0;}
- char *get(char *str);
- int get_int();
- double get_dbl();
- int more() {return input_str[pos] !='\0';}
- void reset() {pos = 0;}
- };
- int main()
- {
- char input_str[100];
- char *p;
- char *in;
- cin.getline(input_str, 99);
- StringParser parser(input_str,"/,\\");
- while(parser.more())
- {
- p = parser.get(in);
- cout << p << endl;
- delete [] p;
- }
- system ("pause");
- return 0;
- }
- //-------------------------------------
- char *StringParser::get(char *str)
- {
- int j = 0;
- char *new_str;
- new_str = new char[100];
- while(strchr(delimiters, input_str[pos]))
- pos++;
- while(input_str[pos] != '\0' && !strchr(delimiters, input_str[pos]))
- if(j<100)
- new_str[j++] = input_str[pos++];
- new_str[j] = '\0';
- return new_str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement