473,651 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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;

inData.open("re verse.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\lab 12\lab12\revers e.cpp(21) : error C2109: subscript requires array or pointer type
M:\C++\Labs\lab 12\lab12\revers e.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\lab 12\lab12\revers e.cpp(23) : error C2109: subscript requires array or pointer type
M:\C++\Labs\lab 12\lab12\revers e.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
1 1854
dmjpro
2,476 Top Contributor
value[index] check this line ..... u declare this as normal varibale but not as an array .....
Mar 23 '07 #2

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

Similar topics

7
3120
by: Fabian Wauthier | last post by:
Hi list, I am trying to dynamically grow a 2 dimensional array (Atom ***Screen) of pointers to a struct Atom (i.e. the head of a linked list). I am not sure if this is the right way to do it: /* Allocate 1st dimension */ if((Screen = (Atom ***) malloc(sizeof(Atom **) * Width)) == NULL) perrexit("malloc");
2
3578
by: Bryan | last post by:
Apologies if this is a noob question, but I've been struggling with this for quite a while... I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string that is displayed in a text box. Once displayed, the text will be copied, transmitted and then pasted (all manually by humans) into a second utility where the string must then be reverse-engineered into the *original* byte array. The byte array will...
8
2463
by: ulyses | last post by:
I'm trying to put pointer to flexible array of structures in other structure. I want to have pointer to array of pixels in screen structure. Here is mine code, but I think it isn't quite all right: struct pixel { int x; int y; int color; };
23
7395
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
8
4751
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. --------------------------------- PROGRAMME -------------------------------- /* K&R2 section 1.9 exercise 1.19
4
2359
by: Tarique | last post by:
/** A palindrome is a number that is the same whether it is read from left-to-right or right-to-left. For example, 121 and 34543 are both palindromes. It turns out that nearly every integer can be transformed into a palindrome by reversing its digits and adding it to the original number. If that does not create a palindrome, add the reverse of the new number to itself. A palindrome is created by repeating the process of reversing the...
7
2447
by: Alenik1989 | last post by:
i have this code which suppose to get a n input from the file and store it in a char array then i have to inverse it..... rhis code isnt complete but im getting a wiered error i see the error when the c++ starts linking not in the compilation procces. my code is #include<iostream> #include<cstring> #include<fstream> int reverse(char* str); using namespace std;
6
1974
by: MN | last post by:
I have 2 questions: 1- Why isn't possible to declare a static char array inside function ? the compiler gives this error: storage size of ‘array’ isn’t constant. 2- Why isn't possible to output the whole array with 2 dimensions from function? my function looks like this:
2
2215
by: raylopez99 | last post by:
Here is a short program demonstrating using IEnumberable, Linq, predicates, extension methods and some tricks and how to convert an IEnumberable sequence into an array. For future reference, not intended as a question. RL Main(): int numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11};
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.