dont understand

while( ( inputChar = static_cast<char>( cin.get() ) ) != ā€˜\nā€™ )

what is the function of this piece of code?
it's equivalent to

1
2
3
4
inputChar = static_cast<char>(cin.get());
while (inputChar != '\n') {
    inputChar = static_cast<char>(cin.get());
}


The purpose of this loop is to wait for the user to press enter and ignore all other inputs.
i need to store characters from an array am i going correct here?

const int maxSize= 100;
char inFix[maxSize];
char inputChar;

cout<<"Please enter your expression and then press enter";
cin>>inputChar;


while ((inputChar=static_cast<char>(cin.get() ))!='\n')

inFix[maxSize]= inputChar;

}
The first problem is the line inFix[maxSize] = inputChar;. You create the array inFix earlier with a size of maxSize elements, but since array indices in c++ start at 0, valid indices for your array are in the range [0, maxSize-1], and maxSize itself is out of range.

Also im not sure if i correctly understood what you want to do. You want to read characters from standart input and store them in an array? What you're doing in the sourcecode you've provided is just reading any number of characters from standart input after the cout<<"Please enter your expression and then press enter";-statement until the user presses enter, but these characters are not stored anywhere.

Maybe you want something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
int i;
cout << "Please enter up to " << maxSize << "characters and press enter" << endl;
for(i=0;i<maxSize;i++) {
    inputChar = cin.get();
    if(inputChar == '\n')    //Break if user pressed enter
       break;
    inFix[i] = inputChar;    //Store character in array
}

//Discard all following characters (if any) on standart input until newline
if(inputChar != '\n') {
    while ((inputChar = cin.get())!='\n')
}
Topic archived. No new replies allowed.