The below code is to make a sentence upper case, and also get every first letter of every word in it, and put it in a different string to be called by the main function.
When I try and call the getFirsts() function I get a breakpoint in a file in the compiler.
So the issue really is just with
When I try and call the getFirsts() function I get a breakpoint in a file in the compiler.
Code:
class charconverter
{
private:
int count;
int last;
public:
string sentence;
string letters;
string setUpper()
{
count = sentence.length();
for (int i = 0; i <= count; i++)
{
sentence[i] = toupper(sentence[i]);
}
return sentence;
}
string getFirsts()
{
count = sentence.length();
for (int i = 0; i < count; i++)
{
if (i == 0)
{
toupper(sentence[i]);
letters = sentence[i];
}
else if (isspace(sentence.at(i)))
{
toupper(sentence[i + 1]);
letters += " ";
letters += sentence[i + 1];
}
}
return letters;
}
};
Code:
string getFirsts()
{
count = sentence.length();
for (int i = 0; i < count; i++)
{
if (i == 0)
{
toupper(sentence[i]);
letters = sentence[i];
}
else if (isspace(sentence.at(i)))
{
toupper(sentence[i + 1]);
letters += " ";
letters += sentence[i + 1];
}
}
return letters;
}
Comment