CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2009
    Posts
    16

    std::cin.getline() space and new line setting input

    Hey there.

    What I'm trying to accomplish is simply. A user enters the input '2 1 3 18' (not including the quotes)
    and all 4 numbers are put into an array.

    This is my code thus far (note variables are set up properly etc the only issue I'm having is saving the input)

    Code:
    for (int i = 0; i < m; ++i){
       counter = 0;
    
       while (counter < n){
           cin.getline(input, 100, ' \n'); //so either a space or a new line is like pressing enter
           aMatrix[i][counter] = (int)input; //I wanted to put (long double)input; but that doesn't work - any ideas?
           counter++;
       }
    }
    Also running the code line for line, the first time cin.getline() is run I'm unable to enter anything.

    Thanks in advance!
    Last edited by Lang; January 15th, 2009 at 11:09 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured