Должен работать так:
Например пишешь 12/23/34
Должен выдать
12
23
34
Только не нужно писать свой код, я хочу понять в чем ошибка
Код: Выделить всё
#include "stdafx.h"
#include <conio.h>
using namespace std;
class StringParser {
private:
int pos;
char* input_str;
char* delimiters;
public:
int more() {
return input_str[pos]!='\0';
}
StringParser(char* inp, char* delim){
input_str = inp; delimiters = delim; pos = 0;
}
char* get(){
int j = 0;
char* new_str;
new_str = new char[100];
while (! strchr(delimiters, input_str[pos])){
new_str[j] = input_str[pos];
pos++;
j++;
new_str[j]='\0';
}
while (strchr(delimiters, input_str[pos]))
pos++;
return new_str;
}
};
int main() {
char input_str[100];
char* ch;
cout << "Enter input line: ";
cin.getline(input_str, 99);
StringParser parser(input_str, "/,");
while (parser.more()){
ch = parser.get();
cout << ch << endl;
delete[]ch;
}
return 0;
}