开发者

printf prints twice for some reason, cout seems okay though [closed]

开发者 https://www.devze.com 2023-02-28 03:10 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I've written a library and I'm trying to statically link it to my main program. My main program is written in C++, but the library is in C. I noticed some of the debugging printf statemen开发者_如何学Gots in my library running twice where they shouldn't for some reason, so I started commenting out code. I'm now left with this (comments excluded):

#include <iostream>
extern "C"
{
    include "audio.h"
}

int main(int argc, char** argv)
{
    std::cout << "Hello" << std::endl;
    audio_test();
    std::cout << "World" << std::endl;
    return 0;
}

The function audio test is not interesting at all. This is from a C file that I'm trying to use in my C++ project.

void audio_test()
{
    printf("TEST\n");
}

The output from my program is this:

Hello
TEST

TEST
World

I have no idea at this point why this is happening.


Call std::ios_base::sync_with_stdio(true) and it will probably work better.

0

精彩评论

暂无评论...
验证码 换一张
取 消