title: C++ Function Completing Before Other Function Finishes
body: <p>I am coding a C++ program to interact with the internet using the C++ REST SDK. I have a main function and a webCommunication function. The code is similar to below:</p>
  
  <pre><code> void webCommunication(data, url)
   {
   //Communicate with the internet using the http_client
   //Print output
   }
  
   int main()
   {
   //Obtain information from user
   webCommunication(ans1, ans2);
   system("PAUSE");
   }
  </code></pre>
  
  <p>However, it seems that the main function is progressing before the webCommunication function is finished. If I make webCommunication a function type of string and have</p>
  
  <pre><code>cout &lt;&lt; webCommunication(ans1, ans2) &lt;&lt; endl;
  </code></pre>
  
  <p>But that still pauses and then prints the data retrieved. Normally, this would be fine, expect I am referring to the returned answer later on in the code. If the webCommunication isn't completed, the application crashes. Is there some kind of wait_until function I can use?</p>
  
  <p>UPDATE: I have tried using a mutex suggested with no success. I also tried starting the function as a thread and then using the .join() with still no success.</p>