passing "\t" escape sequence as command line argument c++

Hey friends, I am new to C++, much appreciate your help on this issue. In the following code, I would like to pass a delimiter (say '\t') as a command line argument. When I parse the delimiter as below, I get a segmentation fault.

command line input:
./a.out "\t"

Program snip:

string delim;
int main(int argc, char *argv[])
{
delim.assign(argv[1]);
...
...
split(parts, line, is_any_of(delim)); << statement causes segmentation fault
}

Replacing assign(argv[1]) with assign("\t") works fine. Could you please let me know the easiest way to resolve my issue? I wanted to receive the delimiter from the command line argument and use it in is_any_of(). I have tried various combinations shown below as command line but nothing helped.

./a.out '\t'
./a.out \t
./a.out \\t (parses as \t but doesn't work)
./a.out \\\t

Thanks,

Raju
Try writing a function that converts C escapes to the corresponding characters.
1
2
3
void convert_c_escapes(char *const s){
	/*figure this out*/
}
Sure, thanks. So, I assume the only way to handle this is to write a new API.
I haven't check it but shouldn't your argument be ./a.out \t instead of ./a.out "\t"?
I mean arguments are passed as strings so you are passing a ""\t"", right?

Maybe this is your problem
Topic archived. No new replies allowed.