Mark As Completed Discussion

Build your intuition. Fill in the missing part by typing it in.

To create a socket in C++, you will need to use the ___________() function from the <sys/socket.h> header. Here's an example of how to create a socket:

TEXT/X-C++SRC
1#include <iostream>
2#include <sys/socket.h>
3
4int main() {
5  int sockfd;
6
7  // Create a socket
8  sockfd = _______;
9
10  if (sockfd == -1) {
11    std::cout << "Failed to create socket" << std::endl;
12    return 1;
13  }
14
15  std::cout << "Socket created successfully" << std::endl;
16
17  return 0;
18}

Write the missing line below.