#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    95
    Rep Power
    11

    view array in a window


    I have wrote a program that creates a 2D array of data from a text file. I want to export that data created by the program to a window that I have created. Is their a way to tell c++ that i want cout to be to the text box that I have created or am I trying to go about this the wrong way?
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    Welcome to the wonderful world of Windows Messaging. You have to communicate with your text box via messages (MFC and other libraries will conceal a lot of that for you, but that is what is going on) and tell it you want it to put some data in its space. Then there are tens of thousands of lines of code buried somewhere that convert your binary string of ASCI data into little images on a patch of screen which your brain interprets as letters. Amazingly compilcated, sometimes amazing that it works at all. As for what code to type to get the end result you want, that depends on the libraries you are using and possibly even on the compiler. You will have to post your attempt along with that info before anyone can help you.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    95
    Rep Power
    11
    Here is my code that creates teh array and I want to compile the end result in MVC++ 6.0

    Code:
    //a 2-D array of numbers
    
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    //defines constants for the array so it is easier to change the dimensions 
    //later
    const int X_MAX=4;
    const int Y_MAX=4;
    
    int main()
    {
    //reads text file into rpogram for later use.
    ifstream temparray;
    temparray.open("/home/justin/c++/temp.txt");
    
     //sets Variables
      int x,y, test[X_MAX][Y_MAX];
      
      //prints message on screen
      cout<<"This is an array of "<<X_MAX*Y_MAX<<" numbers's, its a good start!!\n"<<endl;
    
      //defines the x int
      for(x=0; x<X_MAX; x++){
        
        //defines the y int
        for(y=0; y<Y_MAX; y++){
          
          //defines values for the array
          temparray >> test[x][y];
        
         //prints the array to the screen
          cout<<test[x][y] <<"  ";
        }
      cout<<"\n"<<endl;
    	
        }
      return 0;
    }
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    iostreams don't cut it in Windows. There may be some other techniques (I'm only familiar with MFC and straight-forward Petzold-style Windows programming), but basically for every string you need to call a function like TextOut, passing it the string and the x,y coordinates to start displaying that string. Though you may be able to use strstream to build the string.
  8. #5
  9. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    Except for the location of your input file, your code will run fine on VC6, that is where I do my development and where I compiled and tested the code I've posted. Just put the file in the same directory as the exe and remove the path and it should compile and run exactly the same on *nix and Windows.

    I don't see any attempts to do windowing in your code.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo