title: How to convert a string to uint32_t
body: <p>I have a program which reads the contents of a file line by line, stores each line into a vector of strings, and then prints the contents of the vector. </p>
  
  <p>After reading the file data into the vector of strings, I am attempting to convert each line from <code>string</code> into <code>uint32</code>. Each line of the file consists of <code>32-bit</code> numbers. An example of the input data file <code>(input_file.dat)</code>:</p>
  
  <pre><code>31401402
  67662718
  74620743
  54690001
  14530874
  13263047
  84662943
  09732679
  13839873
  </code></pre>
  
  <p>I would like to convert each of those strings into <code>uint32_t</code>, for a different program I have written which converts these numbers into ASCII format (the program <strong>requires</strong> that <code>uint32_t</code> is used for conversion). </p>
  
  <p>My program so far: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  /*
   * Program to iterate through all lines in file and put them in given vector
   *
   */
  bool getFileContent(std::string fileName, std::vector&lt;std::string&gt; &amp; vecOfStrs)
  {
  
      // Open the File
      std::ifstream in(fileName.c_str());
  
      // Check if object is valid
      if(!in)
      {
          std::cerr &lt;&lt; "Cannot open the File : "&lt;&lt;fileName&lt;&lt;std::endl;
          return false;
      }
  
      std::string str;
      // Read the next line from File untill it reaches the end.
      while (std::getline(in, str))
      {
          // Line contains string of length &gt; 0 then save it in vector
          if(str.size() &gt; 0)
              vecOfStrs.push_back(str);
      }
      //Close The File
      in.close();
      return true;
  }
  
  
  int main()
  {
      //Store contents in this vector of strings
      std::vector&lt;std::string&gt; vecOfStr;
  
      // Get the contents of file in a vector
      bool result = getFileContent("input_file.dat", vecOfStr);
  
      // If above result is true
      if(result)
      {
          // Iterate through the vector contents
          for(std::string &amp; line : vecOfStr)
          {
              //std::cout&lt;&lt;line&lt;&lt;std::endl;      Ignore this print line, it is for debugging only to show that the vector has been correctly filled
  
              //For each line, convert from string to uint32_t
              std::vector&lt;std::uint32_t&gt;new_variable
              new_variable.assign(vecOfStr.begin(), vecOfStr.end());
  
          }
      }
  }
  </code></pre>
  
  <p>In my above attempt, in the <code>for</code> loop underneath the comment which reads "// Iterate through the vector contents", I have attempted to convert each line from a <code>string</code> to <code>uint32_t</code> using the <code>vector::assign</code> function. I did this when researching my problem, and found this function from another SO question: <a href="https://stackoverflow.com/questions/7899838/fastest-way-to-convert-a-stdvector-to-another-stdvector">fastest way to convert a std::vector to another std::vector</a> (author: Vlad, answered Oct 26 '11 at 7:36). When I try to run this code, I receive the following <code>error</code> message: </p>
  
  <pre><code>error: cannot convert ‘std::__cxx11::basic_string&lt;char&gt;’ to ‘unsigned int’ in initialization
  </code></pre>
  
  <p><strong>TO SUMMARISE:</strong> </p>
  
  <p>How can I read the contents of a file line by line, and convert each line into the data type <code>uint32_t</code>? I have ensured that each line is equal to 32-bits. </p>