Monday, 9 September 2013

Push string into vector and send vector through socket

Push string into vector and send vector through socket

Here I am tring to push into vector. And then want to send it via socket
How can I correctly push, print each word and then send entire vector to
socket?
:
int main(int, char**)
{
string text = "token test string";
char* word;
char *str =NULL;
int i=0,j=0;
word = strtok(& text[0], " ");
std::vector<std::string> vec;
while(word!=NULL)
{
cout << word << " : " << text.length() << endl;
word = strtok(NULL, " ");
vec.push_back(word);
str[j]=*word;
j++;
}
for (int i=0; i<vec.size();i++){
cout << vec[i] << endl; ---> Segmentation fault after printing
forst word "tocken"
}
send(*csock, vec, vec.size, 0)) == -1) --> is this correct? give
correction please if wrong
}
Please show me some help with existing code only. Taking another data
structure is not possible me as it encorporate other code of existing
project.

No comments:

Post a Comment