Jump to content
  • Advertisement
Sign in to follow this  
SamuelRS

n00b Alert! Having Problem With Multidemensional Arrays

This topic is 4461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm new to c++ (I've only been doing it for about a week), I put this in general programming due to the fact that it isn't directly linked to games programming (so I couldn't put this thread in that forum). Anywho, this is the code is a using:
#include <iostream>
using namespace std;

int main()
{
int arr = [3][3] { {1,2,3} , {4,5,6} };

cout << "arr[0][0] contains " << arr[0][0] << endl;
cout << "arr[0][1] contains " << arr[0][1] << endl;
cout << "arr[0][2] contains " << arr[0][2] << endl;
cout << "arr[1][0] contains " << arr[1][0] << endl;
cout << "arr[1][1] contains " << arr[1][1] << endl;
cout << "arr[1][2] contains " << arr[1][2] << endl;
cin.get();
}




But for some reason I keep getting loads of errors, I can't seem to work out what I am doing wrong. I read the buildlog, but that makes no sence to me. I am using Visual C++.net. Here is the build log:
Quote:
Build Log Build started: Project: array2d, Configuration: Debug|Win32 Command Lines Creating temporary file "c:\Documents and Settings\Richard\My Documents\Visual Studio 2005\Projects\array2d\array2d\Debug\RSP00001528523132.rsp" with contents [ /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /c /Wp64 /ZI /TP ".\array2d.cpp" ] Creating command line "cl.exe @"c:\Documents and Settings\Richard\My Documents\Visual Studio 2005\Projects\array2d\array2d\Debug\RSP00001528523132.rsp" /nologo /errorReport:prompt" Output Window Compiling... array2d.cpp c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(6) : error C2059: syntax error : '[' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(6) : error C2143: syntax error : missing ';' before '{' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(6) : error C2143: syntax error : missing ';' before '}' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(6) : error C2143: syntax error : missing ';' before ',' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(8) : error C2143: syntax error : missing ';' before '<<' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(9) : error C2143: syntax error : missing ';' before '<<' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(9) : error C2086: 'int cout' : redefinition c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(8) : see declaration of 'cout' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(10) : error C2143: syntax error : missing ';' before '<<' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(10) : error C2086: 'int cout' : redefinition c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(8) : see declaration of 'cout' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(11) : error C2143: syntax error : missing ';' before '<<' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(11) : error C2086: 'int cout' : redefinition c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(8) : see declaration of 'cout' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(12) : error C2143: syntax error : missing ';' before '<<' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(12) : error C2086: 'int cout' : redefinition c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(8) : see declaration of 'cout' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(13) : error C2143: syntax error : missing ';' before '<<' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(13) : error C2086: 'int cout' : redefinition c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(8) : see declaration of 'cout' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(14) : error C2143: syntax error : missing ';' before '.' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(15) : error C2059: syntax error : '}' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(15) : error C2143: syntax error : missing ';' before '}' c:\documents and settings\richard\my documents\visual studio 2005\projects\array2d\array2d\array2d.cpp(15) : error C2059: syntax error : '}' Results Build log was saved at "file://c:\Documents and Settings\Richard\My Documents\Visual Studio 2005\Projects\array2d\array2d\Debug\BuildLog.htm" array2d - 26 error(s), 0 warning(s) It seems alot bigger then all of my other buildlogs, with a lot more errors, I really don't understand it, as I am using a book, and that is the same code.
Thanks for reading, Samuel [Edited by - SamuelRS on May 28, 2006 2:46:26 PM]

Share this post


Link to post
Share on other sites
Advertisement
(note: use source tags for code or things like error messages. click edit on my post to see how to make them)

Quote:

I put this in general programming due to the fact that it isn't directly linked to games programming (so I couldn't put this thread in that forum).


I think "for beginners" would be a more appropriate forum, given that this is simply a beginners mistake [smile]

A 2 dimensional array is typically declared like so:

int arr[3][3] = [3][3] { {1,2,3} , {4,5,6} };

That would make your code:


#include <iostream>
using namespace std;

int main()
{
int arr[3][3] = { {1,2,3} , {4,5,6} };

cout << "arr[0][0] contains " << arr[0][0] << endl;
cout << "arr[0][1] contains " << arr[0][1] << endl;
cout << "arr[0][2] contains " << arr[0][2] << endl;
cout << "arr[1][0] contains " << arr[1][0] << endl;
cout << "arr[1][1] contains " << arr[1][1] << endl;
cout << "arr[1][2] contains " << arr[1][2] << endl;
cin.get();
}

Share this post


Link to post
Share on other sites
Garr, a mistype, lol.

rip off - Hmm, I took the beginners forum for posts that were directly linked with gamedev, I judged that based on the forum description. I'm gonna try to edit my first post now, and see how to do it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!