question interpreting ISO/IEC

I am trying to extract words from a text file and only want to get characters in the range between ! and ~. I know that the computer only understands numbers and so there are number representations of each character. To retrieve a single character from the the text file, I was thinking of doing something like

1
2
3
4
5
6
7
8
9
10
11
12
char c;
string word="";
cin.get(c);
while(c<! && c>~){    //to skip random control characters in the file
  cin.get(c);     
}
while (c>=! && c<=~){ //will add c to string word if within range 
  word+=c;     
  cin.get(c);
  if(isspace(c)) // once hit a space, word is over
     break;
}    


I get an error that says

error: expected primary-expression before ')' token

and another error stating
error: label 'c' used but not defined


I thought c was defined as a char in line 1?
do I need to instead change the conditional for the while loop to
 
while(c<(int)! && c>(int)~){


while ( c >= '!' && c <= '~' )
you do not have to do any type casting. simply use the following condition in your while loop

 
c<'!' && c>'~'
Topic archived. No new replies allowed.