[C++] Send many string with socket?

05/29/2014 16:42 -Unknow#1
Hello everyone , I want to send the same string many times with for(),but i've a problem :
Code:
std::string hello = "hello";
for(int i = 0;i<5;i++){
send(socket[i],hello.c_str(),hello.size,0);
}
with the code i want to send the string "hello" 5 times, but the cycle for, send 1 time the string, can you help me? Thanks
05/29/2014 16:54 th0rex#2
Why would you do socket[i] ??? Just do
send(socket, hello.c_str(), hello.size, 0);
05/29/2014 17:06 Padmak#3
And maybe you want to include () behind .size ..

Padmak
05/29/2014 17:10 -Unknow#4
Quote:
Why would you do socket[i] ??? Just do
send(socket, hello.c_str(), hello.size, 0);
I write socket[i] because i want to send the string 5 times with cycle for and no 1
05/29/2014 17:30 th0rex#5
Just use
send(socket, hello.c_str(), hello.size(), 0);
And maybe look at for loops. You don't need to write socket[i]. The code will still execute 5 times.
05/29/2014 20:19 -Unknow#6
Oh right xD Yes,thanks ;)
05/29/2014 22:35 +Yazzn#7
If you use a standard container (for example std::array or std::vector) you could just do

for (const auto &s : sockets) send(s, hello.c_str(), hello.length(), 0);