PDA

View Full Version : C++ help again



PewterTA
04-19-2009, 05:22 PM
Im trying to convert a string to upper case using this code:

for(int i=0 ; i < ArraySize ; i++)

{

DB[i].name = toupper(DB[i].name);

}


And Im getting this error:

error C2664: 'toupper' : cannot convert parameter 1 from 'std::string' to 'int'

DB[i].name is part of an array of structs and stored in it is a name just like it suggests.

Why am I getting this error, I was under the impression that toupper() could convert an entire string not just one char.

Thanks

PewterTA
04-19-2009, 07:43 PM
Never mind I figured it out.

pendrgn
04-19-2009, 08:12 PM
just curious now, what did you do? and isnt toupper only a char converter?

PewterTA
04-19-2009, 08:57 PM
Yeah it only does a character at a time. So this is what I had to do:

for(int i=0;i < ArraySize;i++)
{
for(int a = 0; a < DB[i].name.length(); a++)
{
DB[i].name[a] = toupper (DB[i].name[a]);
}
}

Which breaks the string into individual characters basically.

FlamingStang
04-20-2009, 11:56 AM
are you taking object oriented next sem? if so get Gaitros

PewterTA
04-20-2009, 01:50 PM
No all I have to take is Intro because I'm just electrical engineering.

Snow
04-25-2009, 09:27 PM
are you taking object oriented next sem? if so get Gaitros

Gaitros? LOL... Think he's too busy playing Director at UCS these days

And ewww..... n^2 loop :/ Also, use ++i instead of i++ if performance is an issue and you aren't using compiler optimization.