| | |
array question
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
The error is correct -- you can't do that in todays C++. Have you been introduced to new/delete?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Mar 2005
Posts: 12
Reputation:
Solved Threads: 0
Thanks for the answers, i can solve my problem now. But i got another question regarding arrays. I tried to make an array of c-style strings with the following code, but got an error:
the error message is: "the compiler is unable to convert from the type char (*) [30] to the type char **."
Why is it so and how can i solve it? :-|
C++ Syntax (Toggle Plain Text)
int main () { char ** strArray = new char [5][30]; //using the array delete [] strArray; return 0; }
the error message is: "the compiler is unable to convert from the type char (*) [30] to the type char **."
Why is it so and how can i solve it? :-|
Multidimensional arrays are actually arrays of arrays, so you need to allocate memory to reflect that:
Then to free them:
The nice thing is that you can index an array allocated like this with the subscript operator:
Not all multidimensional allocation schemes allow you to do that.
C++ Syntax (Toggle Plain Text)
char **p = new char*[rows]; for ( int i = 0; i < rows; i++ ) p[i] = new char[cols];
C++ Syntax (Toggle Plain Text)
for ( int i = 0; i < rows; i++ ) delete [] p[i]; delete [] p;
C++ Syntax (Toggle Plain Text)
cout<< p[i][j] <<endl;
New members chased away this month: 3
![]() |
Similar Threads
- Little Simple array question :) (C)
- Simple array question (C++)
- Simple char array question (C)
- Newbie Constructor / Array question (C++)
- Array Question (C++)
- C++ Array Question (C++)
Other Threads in the C++ Forum
- Previous Thread: code problems
- Next Thread: c++ very new at
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






