error C2664 what am I doin wrong?

I am tryin to take some repetition out of an assignment and having difficulties. Keep getting C2664 errors and maybe yall can tell me wtf I am doing wrong =( Probably something simple but daimen having kinda same problem few posts below =/


// John
// CSCI 1106
// mycodemate prob more advanced

#include <iostream>
#include <cstring>
//#include <strcmp>
using namespace std;

int main () {
const int SIZE = 40;
int count;
char *runner[SIZE];
double *time[SIZE];

count = 1;

while (count != 4)
{
cout << "Enter runners name: ";
cin.getline(runner[count], SIZE);

cout << "Enter runners time: ";
cin.get(time[count], 20);

count += 1; }

cout << runner[1] << " : " << time[1] << endl; // This just for test purpose
cout << runner[2] << " : " << time[2] << endl; // plan on adding strcmp then
cout << runner[3] << " : " << time[3] << endl; // listing them in order by time

return 0;
}

the errors I get are:
Error 1 error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'double *' to 'char *'

We have not covered throwing array in loop yet so been experimenting to complete failure =/

also, how do you copy outta visual 08 and able to display line counts? lol

The get() method cannot accept a double*. If you are going to read it that way, you will need to read it as a char* and then convert it to a double.
ok thanks! I changed it to char instead of double. now when I ran it loaded fine, Enter runners name: (entered a random name), now I have a "xxrunners.exe has encountered a problem and needs to close" so frustrating lol
What did you enter? I can't think of anything off hand that would cause that.
any input I put in I get that error.. figured it might have been just XP so I wrote it on my laptop as well (vista) and I recieved the same thing. The only line I changed was:

double *time[SIZE]; to char * time[SIZE];

copy and see if you get same results =(

// John
// CSCI 1106
// mycodemate prob more advanced

#include <iostream>
#include <cstring>
//#include <strcmp>
using namespace std;

int main () {
const int SIZE = 40;
int count;
char *runner[SIZE];
char *time[SIZE];

count = 1;

while (count != 4)
{
cout << "Enter runners name: ";
cin.getline(runner[count], SIZE);

cout << "Enter runners time: ";
cin.getline(time[count], SIZE);

count += 1; }

cout << runner[1] << " : " << time[1] << endl; // This just for test purpose
cout << runner[2] << " : " << time[2] << endl; // plan on adding strcmp then
cout << runner[3] << " : " << time[3] << endl; // listing them in order by time

return 0;
}


I been stuck trying to figure this little problem out for a day now when I don't even need it for class but want to learn it lol
I will try to sneak into my professors other lab tomorrow and see if he can help me as well, if not my lab is wed night...
Last edited on
You're trying to write to an invalid pointer. runner[0..SIZE-1] and time[0..SIZE-1] are not initialized.
Topic archived. No new replies allowed.