Overloaded << operator

This is a discussion on Overloaded << operator within the C++ Programming forums, part of the General Programming Boards category; It's all working nicely now except for one detail. When I do "outfile << "\n" it doesnt move down a ...

  1. #16
    Registered User
    Join Date
    Mar 2007
    Posts
    16
    It's all working nicely now except for one detail. When I do "outfile << "\n" it doesnt move down a line like it should? Is there another way to do this?

  2. #17
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    could be that you have to flush the output buffer.
    try
    Code:
    cout << endl;
    instead
    Kurt

  3. #18
    Registered User
    Join Date
    Mar 2007
    Posts
    16
    Do you mean outfile << endl; ?
    This is the code in my main while loop:
    Code:
    Set a;
    a.readFromFile(myfile);
    outfile<<a;
    Set d(a.readOperator(myfile));
    Set result(d);
    result.order();
    outfile<<" = "<<result<<"\n";
    How do I get it to end the line after printing the Set result?

  4. #19
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Did you open the file in binary mode? Either open it in text mode, or you'll probably have to write a \r\n pair
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #20
    Registered User
    Join Date
    Mar 2007
    Posts
    16
    This is how I did my file.
    Code:
    ofstream outfile ("C:\\Documents and Settings\\Scott\\Desktop\\C++\\SetOutput.txt");

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Problem using overloaded << operator
    By Zildjian in forum C++ Programming
    Replies: 5
    Last Post: 09-19-2004, 01:09 PM
  4. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM
  5. overloaded << operator doesnt work
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2002, 04:20 AM

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