Hi,
I want to count the number of characters of a string. Try to do it as follows.
int iSpace = 0;
int iLength;
string strTemp("This is a line of text");
iLength = strTemp.length();
cout << iLength << endl;
for(int i = 0; i < iLength; i++)
{
if((strTemp.at(i) == ' ') || (strTemp.at(i) == '\t') || (strTemp.at(i) == '\0'))
{
iSpace ++;
}
}
printf("\nNumber of characters %d", (iLength - iSpace));
Can you guys comments on my code, either this way is ok or bad attempt