Enter data into an array with C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drsunil76
    New Member
    • Sep 2007
    • 1

    Enter data into an array with C++

    hello i am aresearch scholar .i am workingon matrice3s so i want to know that how i can enter a text data FILE in to array in c++ programming.

    if form of text file are like.

    9 8 7 5 6 2 4 1 3 4 23 36
    3 6 2 3 6 2 5 2 3 3 6 89
    5 6 8 9 7 2 3 1 36 56 63
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by drsunil76
    hello i am aresearch scholar .i am workingon matrice3s so i want to know that how i can enter a text data FILE in to array in c++ programming.

    if form of text file are like.

    9 8 7 5 6 2 4 1 3 4 23 36
    3 6 2 3 6 2 5 2 3 3 6 89
    5 6 8 9 7 2 3 1 36 56 63
    Hi Drsunil76! Welcome to TSDN!

    Please ask your question in the C++ Forum, not in the Café.

    Greetings,
    Nepomuk
    Last edited by MMcCarthy; Sep 14 '07, 10:56 AM. Reason: Thread moved to C++

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Originally posted by drsunil76
      hello i am aresearch scholar .i am workingon matrice3s so i want to know that how i can enter a text data FILE in to array in c++ programming.

      if form of text file are like.

      9 8 7 5 6 2 4 1 3 4 23 36
      3 6 2 3 6 2 5 2 3 3 6 89
      5 6 8 9 7 2 3 1 36 56 63
      Sounds like you need file IO.

      Comment

      • ilikepython
        Recognized Expert Contributor
        • Feb 2007
        • 844

        #4
        Originally posted by sicarie
        Sounds like you need file IO.
        I think the best option is to use getline() and then iterate over the string and enter into the array from the string.

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by ilikepython
          I think the best option is to use getline() and then iterate over the string and enter into the array from the string.
          If the OP's sure that's how the input will come in all the time, the OP can use cin. That just won't make it very robust/flexible...

          It just depends on who is going to be using it and for how long. If it's just to run this single simulation and you're sure all the data is only separated by spaces, then I'd recommend cin - it's easy, you don't have to worry about too much. But if multiple simulations are going to be run (like if you do other experiments later and want to use this sort of input method to run some other calculation), I'd agree with ilikepython and say use getline().
          Last edited by sicarie; Sep 14 '07, 03:29 PM. Reason: ilikepython is right

          Comment

          Working...