PDA

View Full Version : 2D Array



ctote
26th January 2010, 06:34
Hey everyone,

I need to print the contents of a 2D array to the screen (command line) for a project I'm working on. Can someone point me in the right direction?

nish
26th January 2010, 07:42
can you print a single element of that array? if so then read about "for loop"

vishwajeet.dusane
26th January 2010, 13:12
Hi

looking at ur problem statement, it sounds very simple. however if you are not able to see anything on the console which u have print then do rememeber to modify your pro file with

CONFIG+=console

There a function in Qt called qDebug() go through that might be useful in your case.

ctote
26th January 2010, 17:54
Thanks guys,

I'm actually very familiar with C++ in general, but am very new to Qt. I'm not sure which functions to call to print to a command line for Qt. Whereas in C++ I would do something like:


ary[10][10];
for (int i = 0 ; i < 9 ; i++)
for (int k = 0 ; k < 9 ; k++)
cout << ary[i][k] << endl ;

I have no idea how to produce output using Qt.

aamer4yu
27th January 2010, 06:37
Did u try running the code ? As said by vishwajeet you need to add CONFIG += console in your .pro file.
Also instead of cout, you may have a look at qDebug

vcp
27th January 2010, 11:57
Hi ctote,

You can try the following code as example:



#include <QCoreApplication>
#include <QDebug>

#include <iostream>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

ary[10][10];

for (int i = 0 ; i < 9 ; i++)
for (int k = 0 ; k < 9 ; k++)
cout << ary[i][k] << endl; // or use qDebug() << ary[i][k];
}


not forgot of use CONFIG+=console and QT -= gui