std::cout outputting in wrong order

This is a discussion on std::cout outputting in wrong order within the C++ Programming forums, part of the General Programming Boards category; I have a vector of structures which contain filenames of type std::string. When I use std::cout to output these strings ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    11

    Question std::cout outputting in wrong order

    I have a vector of structures which contain filenames of type std::string. When I use std::cout to output these strings like so:

    Code:
    for (iter=files1.begin(); iter != files1.end(); iter++)
        std::cout << iter->fileName << "\n";
    std::cout << std::endl;
    for (iter=files2.begin(); iter != files2.end(); iter++)
        std::cout << iter->fileName << "\n";
    I get the output:
    Code:
    file1.txt
    file2.txt
    file3.txt
    file4.txt
    file5.txt
    file6.txt
    file7.txt
    file8.txt
    When I should get:

    Code:
    file1.txt
    file2.txt
    file3.txt
    file4.txt
    
    file5.txt
    file6.txt
    file7.txt
    file8.txt

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    There's not enough code there - are you sure that the files2 container actually has anything in it? The output suggests that the container is empty.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    11
    You were right! I was accidently adding the structures on the end of files1 instead of file2. Opps! I'll remember to read my code more throughly before posting next time

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FFT returning values in wrong order
    By DavidP in forum C# Programming
    Replies: 3
    Last Post: 10-25-2007, 02:15 PM
  2. Problem with ascending order Program
    By cashmerelc in forum C Programming
    Replies: 4
    Last Post: 09-21-2007, 06:36 PM
  3. Printing out in wrong order
    By DarkDot in forum C++ Programming
    Replies: 1
    Last Post: 05-05-2007, 03:56 PM
  4. std::cout or using namespace std or using std::cout
    By ComDriver in forum C++ Programming
    Replies: 13
    Last Post: 01-31-2005, 11:54 AM
  5. can someone check my code and tell me what I'm doing wrong
    By jlmac2001 in forum C++ Programming
    Replies: 7
    Last Post: 09-20-2003, 09:14 PM

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