Thread: Small question about input streams...

  1. #1
    Beginner in C++
    Join Date
    Dec 2007

    Small question about input streams...

    Right, I know this is for a trivial program but I'm trying to improve my problem solving skills by making a program that will calculate the average of any amount of numbers you enter, and I plan to do this using Vectors.

    The question is, I know how to put things into vectors, but I'm not sure about multiple items. Here's what I was thinking:

    cin >> Avg1 >> Avg2 >> Avg3;
    double x;
    while (cin >> x)

    I know why cin >> x works, but will it put all 3 of the values into the vector, or just the latest one I've added (Avg3)?

    If what I've said is hard to understand, can cin hold multiple values ready to used?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    You are using a loop, so it will put values into the vector until EOF is reached (e.g., the user enters CTRL + Z or CTRL + D).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Beginner in C++
    Join Date
    Dec 2007
    That's exactly how I was going to do it, with an End Of File, I just wasn't sure if I could read multiple values into a single variable. Thanks for clearing this up for me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 08:28 PM
  2. neural nets input layer question
    By jianna in forum General AI Programming
    Replies: 3
    Last Post: 04-29-2009, 11:11 AM
  3. Hopefully simple question, input streams
    By dpro in forum C++ Programming
    Replies: 7
    Last Post: 03-09-2006, 01:59 PM
  4. Question about File Input
    By ChristianTool in forum C Programming
    Replies: 12
    Last Post: 04-25-2004, 02:40 PM
  5. Hi all, I have a small question...
    By Pandora in forum Windows Programming
    Replies: 3
    Last Post: 03-16-2003, 06:21 AM