12p Posted November 6, 2011 Share Posted November 6, 2011 (edited) (Hope this is the right place to put this). So, I think I'll try to make *something* on C++. Hope you can (and want to) help me I've got this simple code: #include <iostream.h> int n void main ( ) { char mytable[4] = { 't', 'e', 's', 't' }; for ( n = 0; n < 4; n++ ) { cout<<mytable[n]; } cout<<mytable; } And it says error: 5:declaration syntax error I can't get why it says so. Hope you show me the way. Note. Maybe I'll need further help (lol). That's why the name of the topic is like that Edited November 6, 2011 by Guest Link to comment
Towncivilian Posted November 6, 2011 Share Posted November 6, 2011 You're missing a semicolon after line 3. Also, you should refrain from declaring global variables like you did with int n on line 3. Read here to see why. #include <iostream> void main ( ) { char mytable[4] = { 't', 'e', 's', 't' }; for ( int n = 0; n < 4; n++ ) { std::cout << mytable[n]; } std::cout << mytable; } This isn't exactly the correct subforum - this subforum is supposed to be for MTA-related development discussion. Moved to "General". Link to comment
12p Posted November 6, 2011 Author Share Posted November 6, 2011 Thank you for the very fast reply!!! It's working. My first "string" on C++ Link to comment
Towncivilian Posted November 6, 2011 Share Posted November 6, 2011 You're welcome, and congratulations! See my post again, I added another explanation about accessing the array's elements. Link to comment
12p Posted November 6, 2011 Author Share Posted November 6, 2011 Didn't know about that page and the array error part of mine, thanks again for your help Link to comment
Towncivilian Posted November 7, 2011 Share Posted November 7, 2011 Disregard my comment about accessing the array, I had a brain fart regarding the for loop. Your original for statement was correct. What's the point of the final std::cout << mytable; line? You can't output an array with one line like that - you need to use the for loop you have in order to output the array's contents properly. Don't know why I didn't notice that earlier either... must be this daylight saving stuff here in the US tripping me up. Link to comment
MTA Team jhxp Posted November 7, 2011 MTA Team Share Posted November 7, 2011 If you want to be able to use short cout, cin and other std:: functions syntax (like in your first post), paste this line after includes section: using namespace std; Otherwise you will have to add std:: prefix for each use of cout, cin etc. functions. Link to comment
12p Posted November 7, 2011 Author Share Posted November 7, 2011 (edited) Weird. It works fine without that line, I just use cout without std:: Edited November 7, 2011 by Guest Link to comment
Towncivilian Posted November 7, 2011 Share Posted November 7, 2011 It depends on the compiler you're using. Visual Studio requires using namespace std; or std:: prefixes as in my code example. Link to comment
12p Posted February 6, 2012 Author Share Posted February 6, 2012 Bump. What does this codeline mean? Variable1* Variable2 = NULL I mean, why the * For me, it doesn't make sense. Link to comment
bandi94 Posted February 15, 2012 Share Posted February 15, 2012 that is a pointer most of time's they are used to point at a structure Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now