StringStream Help Please
<p>I am reading a text file with this format:</p>

<blockquote>
  <p>grrr,some text,45.4321,54.22134</p>
</blockquote>

<p>I just have my double valued stored in a string variable.</p>

<p>Why is it only giving me the first digit of the string?</p>

<p>If I start over with just one while loop and a text file of this new format:</p>

<blockquote>
  <p>21.34564</p>
</blockquote>

<p>it works as it should.</p>

<p>The thing is, <code>sLine</code> has the the same value as the one when I started over. What is different is the three nested for loops that most likely is causing the problem.</p>

<p>Here is the code that gets me what I want:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;iomanip&gt;
#include &lt;cstdlib&gt;
#include &lt;sstream&gt;

using namespace std;

int main()
{
    string usrFileStr,
    fileStr = "test.txt",  // declaring an obj string literal
    sBuffer,
    sLine,
    str;

    double dValue ;

    int lineCount = 1;
    int nStart;
    istringstream issm;

    fstream inFile;                  // declaring a fstream obj
    // cout is the name of the output stream
    cout &lt;&lt; "Enter a file: ";
    cin &gt;&gt; usrFileStr;

    inFile.open( usrFileStr.c_str(), ios::in ); 
    // at this point the file is open and we may parse the contents of it


    while ( getline ( inFile, sBuffer ) &amp;&amp; inFile.eof() )
    {
          cout &lt;&lt; "Original String From File: " &lt;&lt; sBuffer &lt;&lt; endl;

          cout &lt;&lt; "Modified Str from File: " &lt;&lt; fixed &lt;&lt; setprecision(2) 
          &lt;&lt; dValue &lt;&lt; endl;
    }

    fgetc( stdin );
    return 0;
}      
</code></pre>

<p>So there it works just like it should. But i cant get it to work inside a for loop or when i have multiple feilds in my text file...</p>

<pre><code>With this code, why is it taken off the decimal?

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;iomanip&gt;
#include &lt;cstdlib&gt;
#include &lt;sstream&gt;
#include &lt;errno.h&gt;

using namespace std;

int main()
{
    string usrFileStr,
    myFileStr = "myFile.txt",  // declaring an obj string literal
    sBuffer, 
    sLine = "";


    istringstream inStream;

    int lineCount = 1;
    int nStart;
    double dValue = 0,
    dValue2 = 0;
    float fvalue;

    fstream inFile;                  // declaring a fstream obj
    // cout is the name of the output stream
    cout &lt;&lt; "Enter a file: ";
    cin &gt;&gt; usrFileStr;


    inFile.open( usrFileStr.c_str(), ios::in ); 
    // at this point the file is open and we may parse the contents of it

    if ( !inFile )
    {
         cout &lt;&lt; "Not Correct " &lt;&lt; endl;
    }


    while ( getline ( inFile, sBuffer ) )
    {
          nStart = -1 ;

          for ( int x = nStart + 1; x &lt; sBuffer.length(); x++ )
          {
              if ( sBuffer[ x ] == ',' )
              {
                   nStart = x;
                   break;
              }

              cout &lt;&lt; sBuffer[ x ];
          }

          for ( int x = nStart + 1; x &lt; sBuffer.length(); x++ )
          {

              if ( sBuffer[ x ] == ',' )
              {    
                   nStart = x;
                   break;
              }

              cout &lt;&lt; sBuffer[ x ];
          }


          for ( int x = nStart + 1; x &lt; sBuffer.length(); x++ )
          {   

              if ( sBuffer[ x ] == ',' )
              {
                   nStart = x;
                   break;
              }

              sLine = sBuffer[ x ];
              inStream.clear();
              inStream.str( sLine );

              if ( inStream &gt;&gt; dValue )
              cout &lt;&lt; setprecision(1) &lt;&lt; dValue;

          }


          for ( int x = nStart + 1; x &lt; sBuffer.length(); x++ )
          {
              if ( sBuffer[ x ] == ',' )
              {
                   nStart = x;
                   break;
              }

              sLine = sBuffer[ x ];     
              inStream.clear();
              inStream.str( sLine );

              if ( inStream &gt;&gt; dValue2 )
                  cout &lt;&lt; setprecision(1) &lt;&lt; dValue2;    
          }

          cout &lt;&lt; ") \n";
          lineCount++;
    }


    cout &lt;&lt; "There are a Total of: " &lt;&lt; lineCount -1 &lt;&lt; " line(s) in the file."
    &lt;&lt; endl;

    inFile.clear();           // clear the file of any errors
    inFile.close();  // at this point we are done with the file and may close it

    fgetc( stdin );
    return 0;
}
</code></pre>

<p>I don't have any other characters to loop over in the first code because im just reading a nice little double value.</p>

<p>In my second code, i have many characters to get to before the one that i want. But regardless, it is still isolated from the other characters and it is still in its own varaible. im to sick to realize what the problem is :/ although i think its the for loops.</p>

<p>I have also tried atof but i get a '0' where the decimal should be.
and strtod is hard because i need im not reading data into a const char *cPtr</p>
