sync_with_stdio() error

This is a discussion on sync_with_stdio() error within the C++ Programming forums, part of the General Programming Boards category; This code (included in all of my source files): Code: //External links/includes #ifndef XOR_LIBRARIES_HEADER #define XOR_LIBRARIES_HEADER #define WIN_32_LEAN_AND_MEAN #include <iostream> ...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    917

    sync_with_stdio() error

    This code (included in all of my source files):
    Code:
    //External links/includes
    
    #ifndef XOR_LIBRARIES_HEADER
    #define XOR_LIBRARIES_HEADER
    
    #define WIN_32_LEAN_AND_MEAN
    
    #include <iostream>
    #include <fstream>
    #include <cstdlib> //rand(), system()
    #include <ctime> //used for random seed
    #include <windows.h> //ShellExecute()
    
    std::ios::sync_with_stdio(false);  //a bit of optimization, because I don't use C i/o streams        
    
    #endif
    Is generating these errors:
    Code:
    std::ios::sync_with_stdio(false);
    error: expected `,' or `;' before '(' token  
    error: expected constructor, destructor, or type conversion before '(' token
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    You can't have a function call at that scope.

    If you're not sure what you're doing or why, maybe that should be the question.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    917
    Then the question is: within which source file should I call the function?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    How about this first?
    Code:
    std::ios::sync_with_stdio(false);  //a bit of optimization, because I don't use C i/o streams
    If you are not using C I/O streams, then why -- as an "optimization" -- are you trying to synchronize with them?

    [edit]
    Quote Originally Posted by CodeMonkey
    Then the question is: within which source file should I call the function?
    http://www.dinkumware.com/manuals/?m...ync_with_stdio
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    917
    I'm "desynchronizing" to allow cout to be fully buffered, so it performs better.
    >>You can call it reliably only before performing any operations on the standard streams.
    Yes, but apparently not in the header scope. How can I ensure... oh, I'll just put it before main(). Der. Thanks.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by CodeMonkey
    oh, I'll just put it before main(). Der. Thanks.
    Okay, you really ought to understand better what you're doing first.

    I'd also recommend checking the return value to verify you didn't go through the effort to change false to false.

    Quote Originally Posted by CodeMonkey
    I'm "desynchronizing" to allow cout to be fully buffered, so it performs better.
    That suspiciously sounds like a new form of premature optimization that I had not heard of before.

    So profiling your program indicated that there is a bottleneck in the standard C++ I/O streams?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    917
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Dave_Sinkula
    That suspiciously sounds like a new form of premature optimization that I had not heard of before.

    So profiling your program indicated that there is a bottleneck in the standard C++ I/O streams?
    As I suspected, I presume.
    http://www.daniweb.com/techtalkforums/post39209-6.html
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    917
    *sigh* I stand corrected. Thanks for the advice.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

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