I have one problem to use std::vector instead of std::array. Most people says they serve for same purpose except their way of memory allocation (array allocates memory statically for its elements and vector allocates memory dynamically ). To clear my understanding I tried something but failed.
I had my running code using array was working fine.
char userInput[MAX_DATA] = { '\0' };
std::cout<<"\enter some char: ";
std::cin.getline(userInput, MAX_DATA);
int bytes_sent = send(socketFD, userInput, strlen(userInput), 0);
//send function definition send(__in SOCKET s, __in_bcount(len) const char FAR * buf, __in int len, __in int flags);
By using vector I have changed my code lines by instead of above defined code:
std::vector<char> userbuffer;
std::cout<<"\enter some char: ";
cin>>input;// i only want to send only the data i entered here in run time.
int bytes_sent = send(socketFD, userbuffer, userbuffer.size(), 0);
//error C2664: 'send' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'const char* '
I am really new to c++ STL concepts. Can someone please help me find out what I am doing wrong? My intention to do this is to see dynamic memory allocation.