Dec 21, 2016 at 10:48am UTC
Hi,
How to split const char* into two const char*.
I have one const char* with + in between which need to split.
Eg: abcd+efgh in two const char* abcd & efgh.
Thanks
Dec 21, 2016 at 11:00am UTC
If you store the string in a non-const char array you can use strtok.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <cstring>
int main()
{
char str[] = "abcd+efgh" ;
const char * first = std::strtok(str, "+" );
const char * second = std::strtok(nullptr , "+" );
std::cout << first << std::endl;
std::cout << second << std::endl;
}
abcd
efgh
http://www.cplusplus.com/reference/cstring/strtok/
Last edited on Dec 21, 2016 at 11:02am UTC