Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. output

output

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sardinka
    wrote on last edited by
    #1

    I have 2 arrays and I need to display data this way: array1 array2 data1 data1 data2 data2 data3 data3 How do I dot this?

    D N R 3 Replies Last reply
    0
    • S sardinka

      I have 2 arrays and I need to display data this way: array1 array2 data1 data1 data2 data2 data3 data3 How do I dot this?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      for (int x = 0; x < 2; x++)

      << ' ' << array2[x] << endl;


      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

      1 Reply Last reply
      0
      • S sardinka

        I have 2 arrays and I need to display data this way: array1 array2 data1 data1 data2 data2 data3 data3 How do I dot this?

        N Offline
        N Offline
        Navin
        wrote on last edited by
        #3

        IT depends - if you know they are the same length, and know what that length is, you can do this (using "cout" as an example, you can use print, or do it to a list box, or whatever.)cout << "Array 1\t\tArray 2" << endl; for(int i = 0; i < sizeOfArrays; i++) { cout << array1[i] << "\t\t" << array2[i] << endl; }
        Now, if your array sizes are different, it's tricker. You either need array classes (e.g., CArray or stl::vector), or variables specifying the size of each array, and then in the for loop, check to make sure you're not out of bounds, e.g. (assuming array1 and array2 are STL vectors):cout << "Array 1\t\tArray 2" << endl; int arraySize = array1.size(); if(array2.size() > arraySize) arraySize = array2.size(); for(int i = 0; i < arraySize; i++) { if(i < array1.size()) cout << array1[i] << "\t\t"; else cout << "(null)\t\t"; if(i < array2.size()) cout << array2[i] << endl; else cout << "(null)" << endl; }

        You can tweak the formatting as necessary. If your nose runs and your feet smell, then you're built upside down.

        S 1 Reply Last reply
        0
        • S sardinka

          I have 2 arrays and I need to display data this way: array1 array2 data1 data1 data2 data2 data3 data3 How do I dot this?

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          Ugh, this smells like homework. :suss: /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

          1 Reply Last reply
          0
          • N Navin

            IT depends - if you know they are the same length, and know what that length is, you can do this (using "cout" as an example, you can use print, or do it to a list box, or whatever.)cout << "Array 1\t\tArray 2" << endl; for(int i = 0; i < sizeOfArrays; i++) { cout << array1[i] << "\t\t" << array2[i] << endl; }
            Now, if your array sizes are different, it's tricker. You either need array classes (e.g., CArray or stl::vector), or variables specifying the size of each array, and then in the for loop, check to make sure you're not out of bounds, e.g. (assuming array1 and array2 are STL vectors):cout << "Array 1\t\tArray 2" << endl; int arraySize = array1.size(); if(array2.size() > arraySize) arraySize = array2.size(); for(int i = 0; i < arraySize; i++) { if(i < array1.size()) cout << array1[i] << "\t\t"; else cout << "(null)\t\t"; if(i < array2.size()) cout << array2[i] << endl; else cout << "(null)" << endl; }

            You can tweak the formatting as necessary. If your nose runs and your feet smell, then you're built upside down.

            S Offline
            S Offline
            sardinka
            wrote on last edited by
            #5

            The size of the array is the same, because I am using the parallel array.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups