All welcome. I'm trying to get an image on the socket.

There was such a problem:

It is necessary to create an array from the array in order to create an array exclusively with an image, without any garbage.

Tried to do this:

while (ignored_error != boost::asio::error::eof) { boost::array<char, 10000> RECV_DATA; // ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ "с мусором" size_t ImageSize = image_recver.read_some( boost::asio::buffer(RECV_DATA), ignored_error); char complete[ImageSize]; // Π”ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ массив Π±Π΅Π· мусора, ΠΈΡΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ само ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ for (int i = 0; i < ImageSize; i++) { complete[i] = RECV_DATA[i]; // заполняСм массив } cout << ImageSize << " : " << complete.size() << endl; // убСТдаСмся, Ρ‡Ρ‚ΠΎ Ρ€Π°Π·ΠΌΠ΅Ρ€ массива схоТ с Ρ€Π°Π·ΠΌΠ΅Ρ€ΠΎΠΌ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½ΠΎΠ³ΠΎ изобраТСния } 

But I got the following error:

E0028 expression must have a constant value. OpenCvTest D: \ C ++ Projects \ ImageRecvTest \ ReceiveImage.cpp 33 the value of the variable "ImageSize" (declared in line 30) cannot be used as a constant

I tried this:

  char *complete[] = new char[ImageSize]; 

But here I got an error:

E0520 for an aggregate object, initialization is required using "{...}"

What to do?

  • char * complete = new char[ImageSize]; , char *complete[] declares an array of pointers - VTT

1 answer 1

Use vector std :: vector a (size);