-5

I am making a map system here is a sample of my code in c++:

char map2[11][30] = {
"#############################",
"#@ #e   <                   #",
"#  #    #                   #",
"#  ############^#############",
"# ############  #############",
"#            # #            #",
"#            # #            #",
"#      *              *     #",
"#            # #            #",
"#            # #            #",
"#############################",

};

but it does not show the 2nd "#############################".

I print by:

cout << map2[] << endl;
Hami
  • 704
  • 2
  • 9
  • 27
  • 1
    How exactly do you expect anyone to figure out what's wrong with code that prints this "map" without actually seeing the code, or without even explaining whether the code in question is C++ or C#. These are two completely different languages. Fail. – Sam Varshavchik Jun 10 '17 at 23:09
  • I am surprised it shows the 1st "#############################", because this is a declaration, it should not show anything. – Mike Nakis Jun 10 '17 at 23:11
  • 2
    I agree with @SamVarshavchik, please provide us with a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Hami Jun 10 '17 at 23:12

4 Answers4

1

Ok, you have a lot of errors with your code. If you printed it properly by iterating over all the elements, it should work correctly, as follows:

#include <iostream>

int main()
{
    char map2[11][30] = {
        "#############################",
        "#@ #e   <                   #",
        "#  #    #                   #",
        "#  ############^#############",
        "# ############  #############",
        "#            # #            #",
        "#            # #            #",
        "#      *              *     #",
        "#            # #            #",
        "#            # #            #",
        "#############################",
    };
    for (int i = 0; i < 11; ++i) {
        for (int j = 0; j < 30; ++j) {
            std::cout << map2[i][j];
        }
    }
}

However, this assumes that you are not printing new lines at the end of each part of the map, just printing the board. You could also change the loop to the better:

for (int i = 0; i < 11; ++i) {
     std::cout << map2[i] << "\n";
}

This now accounts for new lines in the array so the board looks like, well, a board.

Example here

I also recommend reading one of these books, because you don't seem to have a very solid grasp of C++.

Arnav Borborah
  • 11,357
  • 8
  • 43
  • 88
1

Here is shown how to output the map in two different ways

#include <iostream>

int main()
{
    char map2[11][30] = {
        "#############################",
        "#@ #e   <                   #",
        "#  #    #                   #",
        "#  ############^#############",
        "# ############  #############",
        "#            # #            #",
        "#            # #            #",
        "#      *              *     #",
        "#            # #            #",
        "#            # #            #",
        "#############################",
    };

    for (const auto &row : map2) std::cout << row << std::endl;

    std::cout << std::endl;

    for (size_t i = 0; i < sizeof(map2) / sizeof(*map2); i++)
    {
        std::cout << map2[i] << std::endl;
    }
}

The program output is

#############################
#@ #e   <                   #
#  #    #                   #
#  ############^#############
# ############  #############
#            # #            #
#            # #            #
#      *              *     #
#            # #            #
#            # #            #
#############################

#############################
#@ #e   <                   #
#  #    #                   #
#  ############^#############
# ############  #############
#            # #            #
#            # #            #
#      *              *     #
#            # #            #
#            # #            #
#############################
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

Iterate over the elements inside that array and print out each one. I cannot comment, but this is my answer. Also I'm not even sure if this is the problem. Its just a WAY better way to go about doing it assuming youre not doing it this way.

Please please please make your question a bit better next time you ask :)

Verideth
  • 7
  • 8
0

Let me preface my answer with this: Please provide more code the next time you ask your question. You cannot say your code does not print the last line without providing the piece of code actually printing!

This works for me:

#include <stdio.h>

using namespace std;


int main() {
    char map2[11][30] = {
"#############################",
"#@ #e   <                   #",
"#  #    #                   #",
"#  ############^#############",
"# ############  #############",
"#            # #            #",
"#            # #            #",
"#      *              *     #",
"#            # #            #",
"#            # #            #",
 "#############################",};
    for (int i=0;i<11;i++){
        printf("%s \n", map2[i]);
    }

    return 0;
}

Output:

#############################                                                                                                                                                        
#@ #e   <                   #                                                                                                                                                        
#  #    #                   #                                                                                                                                                        
#  ############^#############                                                                                                                                                        
# ############  #############                                                                                                                                                        
#            # #            #                                                                                                                                                        
#            # #            #                                                                                                                                                        
#      *              *     #                                                                                                                                                        
#            # #            #                                                                                                                                                        
#            # #            #                                                                                                                                                        
############################# 
Hami
  • 704
  • 2
  • 9
  • 27