| | |
adding data into an char array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
hello, ok
here it goes...
I've got a char array but it doesnt want to let me add data to it!! I cant figure out why
[php]
//skip the program heres the line...
int chararry[12][10] = {Jan, Feb....}
[/php]
but I keep getting an error saying its not been initialized... I've tried google but nothing :eek:
here it goes...
I've got a char array but it doesnt want to let me add data to it!! I cant figure out why
[php]
//skip the program heres the line...
int chararry[12][10] = {Jan, Feb....}
[/php]
but I keep getting an error saying its not been initialized... I've tried google but nothing :eek:
•
•
•
•
Originally Posted by Acidburn
hello, ok
here it goes...
I've got a char array but it doesnt want to let me add data to it!! I cant figure out why
[php]
//skip the program heres the line...
int chararry[12][10] = {Jan, Feb....}
[/php]
but I keep getting an error saying its not been initialized... I've tried google but nothing :eek:
And 'Jan', 'Feb'
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
umm! sorry
[php]int chararry[12][10] = {"Jan", "Feb"} [/php]
i get the following errors
F:\University work\Computer Science\C++\New Folder\montharray.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
F:\University work\Computer Science\C++\New Folder\montharray.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
i sorted it.... But I do hate pointers!!!! Don't understand how to use them
[php]int chararry[12][10] = {"Jan", "Feb"} [/php]
i get the following errors
F:\University work\Computer Science\C++\New Folder\montharray.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
F:\University work\Computer Science\C++\New Folder\montharray.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
i sorted it.... But I do hate pointers!!!! Don't understand how to use them
Hi Acidburn, change the " to ' Ive tried it out and got the exact error message you got:
C++ Syntax (Toggle Plain Text)
C:\Program Files\Microsoft Visual Studio\MyProjects\Testing\Testing.cpp(14) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast C:\Program Files\Microsoft Visual Studio\MyProjects\Testing\Testing.cpp(14) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast Error executing cl.exe. Testing.obj - 2 error(s), 0 warning(s)
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
•
•
•
•
Originally Posted by Narue
>int chararry[12][10] = {"Jan", "Feb"}
Your declaring an array of integers but trying to initialize it with strings. Do you see anything wrong with that? If not then maybe a strongly typed language like C++ isn't your cup of tea.
btw a string array would mean you only need a one dimension array:
as the lengths are initialised by its constructor. The array is then MUCH easier to work with when you only have a single dimension.
C++ Syntax (Toggle Plain Text)
#include <string> // the string class is in the string library (std name space) using namespace std; string months[12] = { "January", "February"...... };
as the lengths are initialised by its constructor. The array is then MUCH easier to work with when you only have a single dimension.
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Compile and linking problems with Microsoft Visual C++
- Next Thread: overloading [] with 2 dimensional arrays
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector visualstudio win32 windows winsock word wordfrequency wxwidgets






