title: Read floats from a .txt file
body: <p>How can I read floats from a .txt file. Depending on the name at the begining of each line I want to read a different number of coordinates. The floats are seperated by "space".</p>
  
  <p>Example: <code>triangle 1.2 -2.4 3.0</code></p>
  
  <p>The result should be :
  <code>float x = 1.2 / float y = -2.4 / float z = 3.0</code></p>
  
  <p>The file has more lines with differens shapes which can be more complex but I think if i know how to do one of them I can do the others on my own.</p>
  
  <p>My Code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main(void)
  
  {
  
      ifstream source;                    // build a read-Stream
  
      source.open("text.txt", ios_base::in);  // open data
  
      if (!source)  {                     // if it does not work
          cerr &lt;&lt; "Can't open Data!\n";
      }
      else {                              // if it worked 
          char c;
          source.get(c);                  // get first character
  
          if(c == 't'){                   // if c is 't' read in 3 floats
              float x;
              float y;
              float z;
              while(c != ' '){            // go to the next space
              source.get(c);
              }
              //TO DO ??????              // but now I don't know how to read the floats          
          }
          else if(c == 'r'){              // only two floats needed
              float x;
              float y;
              while(c != ' '){            // go to the next space
              source.get(c);
              }
              //TO DO ??????
          }                                
          else if(c == 'p'){              // only one float needed
              float x;
              while(c != ' '){            // go to the next space
              source.get(c);
              }
              //TODO ???????
          }
          else{
              cerr &lt;&lt; "Unknown shape!\n";
          }
      }   
   return 0;
  }
  </code></pre>