By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,852 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

C++ Array importing int's from .dat and reverse out to screen

P: 1
I know this code is wrong, and I am paying the price now for focusing on Linear last semester during the first half of C++, but I am trying to figure this out. Can anyone help? I want to make sure:
1. I am importing the file externally
2. Why this doesn't work with the variables I have chosen.

const int MAX = 10;

int main ()
int numbers[MAX]; //variable that stores the integers
ifstream inData; //enables istream
int value;
int index;"reverse.dat");
for (index = 0; index < MAX; index++)

inData >> value[index];
numbers = value[index];

for (index = MAX - 1; index >= 0; index--)
cout << numbers[index];
return 0;

Error codes:
M:\C++\Labs\lab12\lab12\reverse.cpp(21) : error C2109: subscript requires array or pointer type
M:\C++\Labs\lab12\lab12\reverse.cpp(21) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
M:\C++\Labs\lab12\lab12\reverse.cpp(23) : error C2109: subscript requires array or pointer type
M:\C++\Labs\lab12\lab12\reverse.cpp(23) : error C2440: '=' : cannot convert from 'int' to 'int [10]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
Mar 23 '07 #1
Share this Question
Share on Google+
1 Reply

P: 2,476
value[index] check this line ..... u declare this as normal varibale but not as an array .....
Mar 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.