I was trying to make a header file that will convert strings to lowercase, uppercase, but I'm having a problem in capitalizing every word in a string.
These codes work on the main() but I can't get it to work on a function or header. The problem is with "strlen". Is there way to improvised the code or do I have to place this in the main()? I want to place all the convertion functions in the same header if possible.
1 2 3 4 5 6 7 8 9 10 11
inline std::string& strcps(std::string& z)
{
z[0] = toupper(z[0]);
int d = strlen(z);
for (int i = 1; i < d; ++i)
{
if(z[i] == ' ') // If a space
z[i+1] = toupper(z[i+1]);
}
return z
}
I need at least a hint to get around this.
Thanks in advance.
Cheers!
Sorry, I'm trying to learn C++ from a book, and that's about the only code that's in there. It's a beginner's book though.
It's working now. Many thanks.