I am trying to write a C++ function that splits a std::string containing a URL into its components. I need to copy the components into this structure:
typedef struct urlstruct {
string protocol;
string address;
string port;
string page;
} urlstruct;
Here is the function so far:
int parseAnnounce2(string announce, urlstruct *urlinfo){
int i;
if(announce.find("://") != string::npos){
// "://" found in string, store protocol
for(i = 0; i < announce.find("://"); i++){
}
} else {
// No "://" found in string
}
return 0;
}
I need to copy the characters before the '://' sequence into the urlinfo->protocol string. What is a good way of doing this?
I know that I can't assign it using the following line of code, because the protocol string has not been initialized to contain that memory.
urlinfo->protocol[i] = announce[i];