Need help with arrays and file I/O

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #16
    Originally posted by dkwan
    I have the integers 8 55 26 99 in the input file but it is being displayed as 8552699.
    i modified the code as hsn asked me..
    Code:
        cout <<"The four integers of the input file are: " ;<< n1 <<n2 <<n3 <<n4 <<endl;
    Uhhhh. That's how you are printing them out. You do see that those are your numbers, and you're not putting spaces between the output statements, right?

    Just as an aside, I'm surprised this compiles with that semi-colon in there. But I haven't ever tried to split cout like that, it might be possible.
    Last edited by sicarie; Feb 24 '08, 04:20 PM. Reason: Just as an aside

    Comment

    • dkwan
      New Member
      • Feb 2008
      • 13

      #17
      how to do that??? help me plz

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #18
        Originally posted by dkwan
        how to do that??? help me plz
        How to do what? Insert spaces in there? Dude, if you can't figure that out at this point, there's not much I can do to help you.

        You know how to output strings and chars, right? Well, that's all you're doing, only in between each of your variables...

        Comment

        • dkwan
          New Member
          • Feb 2008
          • 13

          #19
          sorry..not the whitespaces..i know how to do that. in fact i was going to ask about how to read from a file if i am using array..for eg if i have integers 24 5 9 89 in the file and i want to sort it,i will have to use an array.am i right?

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #20
            Originally posted by dkwan
            sorry..not the whitespaces..i know how to do that. in fact i was going to ask about how to read from a file if i am using array..for eg if i have integers 24 5 9 89 in the file and i want to sort it,i will have to use an array.am i right?
            Well, you don't have to, but if you're going to sort anything more than a few, you really want to, cause it'll get annoying instantiating all those variables.

            If you're going to read in several, you need to know exactly how many. You create a loop to iterate that many times, and cin each individually. If the numbers are not delimited by a whitespace (like if they are in a csv doc or something), you won't be able to use cin.

            Then you can implement your sorting algorithm of choice on that array.

            Comment

            • dkwan
              New Member
              • Feb 2008
              • 13

              #21
              thanks for helping me..

              Comment

              Working...