Simple ASCII problem I can't figure out.

Predeclared variable works, so if one comments out the cin statement, it goes through until the end.
when using CIN to capture the input, it terminates at the first space.
the exercise says not to use CLR, but c++/cli.
I still can't figure out why the user input string is terminating, but the declared string is not.
I am using vc++ express 2008, second exercise from Hortons Learn VC++ 2010
chapter 4.
Declare a character array, and initialize it to a suitable string. Use a loop to change every other character to uppercase. HINT. in ASCII character set, Uppercase is 32 less than lowercase counterpart.
I feel stupid, like I should be getting this already.
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
#include<iostream>
#include<iomanip>

using std::cout;
using std::cin;
using std::setw;
using std::endl;

int main()
{
char ss_string[] = "Why does this work, but CIN >> will not";
short ii_count = 0;
cout << "Input some text, to convert every other letter to uppercase.";
cout << endl;
cin >> ss_string;
cout << endl;
do
{

if(ss_string[ii_count] >= 'a' && ss_string[ii_count]<='z')
{
if(ss_string[ii_count - 1] >= 'A' && ss_string[ii_count - 1]<='Z')
{
//empty struct to skip the code if the prior letter is Uppercase
}else {ss_string[ii_count] = (ss_string[ii_count] - 32);};
}

ii_count ++;

}while(ss_string[ii_count] != '\0');
cout << ss_string;
cout <<endl;

return 0;

}
std::cin returns an istream object. Try declaring ss_string as std::string rather than char*. You can then use ss_string.c_str() in place of the character array.
The exercise specifically asked me to use a character string. I am not sure why I would have to do this, but that is what it has asked. It seems to me it would be easier to use a string as such, and convert with toupper and so on.
I am assuming that there is some kind of wisdom to the way I am asked to these problems.
Granted the exercise did not ask me to get user input, so....
It looks like in this case it is the difference between cin and cin.getline.

cin only takes the input up until it encounters a space, cin.getline performs a conversion.

You did however, teach me something this book hasn't.
std::string
I was wondering why c++ had no basic string.
Topic archived. No new replies allowed.