very simple program with string manipulation not working

I have this program here. Only problem is it isn't converting to uppercase.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>
#include <ctype.h>
#include <string.h>
using namespace std;


string check(string b);

int main()
{

string hip;

cout << "Enter line: ";
getline(cin, hip);
try
{
check(hip);
}
catch(string i)
{
cout << "Error Occurred: i is blank.";
return -1;
}
cout << endl << hip << endl;

return 0;
}

string check(string b)
{
if (b.empty() == 1)
throw b;


for (int i = 0; i < b.size(); i++)
b[i] = toupper(b[i]);

return b;
}


It is very much a runtime error. Everything compiles peachy.
You're never doing an reassigning hip.

Please don't refer to logic bugs as "runtime errors". I thought you had a problem with exceptions or something.
Last edited on
what do you mean by reassigning?
Last edited on
Indentation is your friend.

Also
hip = check(hip);

Or take a string& as parameter in the function.
Last edited on
Topic archived. No new replies allowed.