entering into arrays/ crazy compiler problem

I am working on what should probably be a pretty basic coding project, requiring me to write a few functions sending values back to main. I am compiling after completing each one and am stuck on this one because I keep getting a crazy compiler message. Here is the code i have written:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  //this function accepts student records input from the keyboard and saves them in the arrays for student ID, test 1 and test 2
int inputStudentRecords (int stuID [], int test1 [], int test2[], int count)
{
        int response = 1;
        while (response == 1)
        {
                cout << "Enter '1' if you have student records to input. Otherwise, enter any other digit.  ";
                cin >> response >> endl;
                if (response == 1)
                {
                        cout << "Enter student ID: ";
                        cin >> stuID [count] >> endl;
                        cout << "Enter student's grade for Test 1: ";
                        cin >> test1 [count] >> endl;
                        cout << "Enter student's grade for Test 2: ";
                        cin >> test2 [count] >> endl;
                }
                count++;
        }
        return count;
}


and here is the error I am getting after using g++:

tests.cpp:77: error: no match for ‘operator>>’ in ‘std::cin.std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(& response))) >> std::endl’
/usr/include/c++/4.4/istream:119: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:123:

i am using the library <iostream> before the main function, so i am completely confused why it says there is no match for the in operator. Help is greatly appreciated!!
change cin >> response >> endl; to cin >> response; and see if that helps

do the same thing on lines 12, 14, and 16
Last edited on
Alright, I don't understand why that fixed the problem, but it did indeed!

HOWEVER…

instead of getting all kinds of craziness when I compile, I'm still getting this message:

tests.cpp:30: error: stray ‘\342’ in program
tests.cpp:30: error: stray ‘\200’ in program
tests.cpp:30: error: stray ‘\271’ in program

Thanks for your help yanson
Alright, I don't understand why that fixed the problem, but it did indeed!

What you were trying to do was store input into the endl manipulator, which makes no sense. Use endl with cout, not cin.

As for error you're getting now can't say, but the problem is on line 30 of tests.cpp. See if you can see what's going on, or post relevant code.
I see. Good to know as a beginner. I figured out what the error was. Thanks for the help guys!
Topic archived. No new replies allowed.