tags:

views:

150

answers:

2

Upon debugging i had thought i did it right. But it was only the first member as the first element in the vector that was corrected.

while ( !inFile->eof() )
{
    getline( *inFile, str1, ',' );      
    sStruct.str1 = str1;
    getline( *inFile, str2, ',' );
    sStruct.str2 = str2;
    getline( *inFile, str3, ',' );
    sStruct.str3 = atof( str3.c_str() );
    getline( *inFile, str4 );
    sStruct.str4 = atof( str4.c_str() );

    myLength = sStruct.str1.length();

    for( ; sIndex < myLength; sIndex++ )
    { 
        if ( 97 <= str4[sIndex] && str4[sIndex] <= 122 )
        {
            str4[sIndex] -= 32;
        }
    }   

    sStruct.str1 = str1;
    vectorData->push_back( sStruct );
}

Implementing this code under the method that i chose to read the file in, only changes the first struct member, in this case str1, to all upper case characters. All characters remain uneffected for the same structure member, str1.

What is my loop not doing?

+3  A: 

As already stated in the comments there are a few things you should look at in your code first:

  • what is the value of sIndex, before you enter this while-loop?
  • why are you working with str4[] in the for-loop but get the length and do assigns on str1?
  • are you really sure, that only str1 is changed to uppercase? the given code doesn't do that...
  • don't do the uppercase-calculation yourself but use the toupper() method instead
Kosi2801
+1  A: 

I would suggest using transform from the header algorithm to convert, it's cleaner:

transform( str4.begin(), str4.end(), str4.begin(), toupper );
Anders K.