Small question about input streams...

This is a discussion on Small question about input streams... within the C++ Programming forums, part of the General Programming Boards category; Right, I know this is for a trivial program but I'm trying to improve my problem solving skills by making ...

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

    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:

    Code:
    cin >> Avg1 >> Avg2 >> Avg3;
    
    double x;
    
    while (cin >> x)
    {
    	Average.pushback(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
    Location
    Singapore
    Posts
    20,975
    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).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Beginner in C++
    Join Date
    Dec 2007
    Posts
    34
    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, 12: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, 05:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21