#include <iostream>
using namespace std;
int main () {
int x;
cin>>x>>"\t";
int A = A[x];
return 0;
}
the error is "subscript requires array or pointer type"
how can i input my desired number of size by using cin for x??? help
#include <iostream>
using namespace std;
int main () {
int x;
cin>>x>>"\t";
int A = A[x];
return 0;
}
the error is "subscript requires array or pointer type"
how can i input my desired number of size by using cin for x??? help
Jump to PostYou cannot input into the string "\t".
Jump to Posti dont really understand what you are attempting.
could u be more specific?
You cannot input into the string "\t".
i dont really understand what you are attempting.
could u be more specific?
1.I think you are trying to create an int array with a size which input by the user.
First, the syntax for creating an integer array is
int array_name[size];
Secondly,
cin is used to input data into a variable and hence cin>>x>>"\t" is wrong
The >>"\t" part is incorrect as it is not a variable.
To accept a value for integer x through user input, the syntax is
cin>>x;
So the proper code would be
#include <iostream>
using namespace std;
int main () {
int x;
cin>>x;
int A[x];
return 0;
}
2.If you are looking to input values into the array, use the code:
cin>>A[0];
This code will accept a value for the first element (which has index no. 0) of array A.
For the next element, use A[1], A[2] and so on...
to anantk
just a newb myself but i was under the impression that the size of an array had to be specified by a constant not a variable entered by the user. i may have this wrong.
to anantk
just a newb myself but i was under the impression that the size of an array had to be specified by a constant not a variable entered by the user. i may have this wrong.
AFAIK, what you say holds true for the older compilers like Borland/Turbo C++..
Most new compilers (like CodeBlocks, which I use) support variable sized arrays as in my previous post.
Older ones like Turbo C++ need to use dynamic memory allocation (using 'new', pointers etc.)
Someone asked about that here too : http://www.cplusplus.com/forum/beginner/1601/
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.