小编Ram*_*ter的帖子

C++ cout打印很慢

我注意到如果我使用cout打印出长字符串(char*),它似乎一次打印1个字符到Windows 7,Vista和Linux(使用putty)的屏幕上,使用Windows上的Visual C++ 2008和Linux上的G ++.Printf是如此快得多,我实际上从cout切换到printf,用于我的项目中的大多数打印.这让我感到困惑,因为这个问题让我觉得我是唯一一个有这个问题的人.

我甚至写了一个cout替换,看起来像是在我的comp上击败cout的裤子 -

class rcout
{
public:
    char buff[4096];
    unsigned int size;
    unsigned int length;

    rcout()
    {
        size = 4096;
        length = 0;
        buff[0] = '\0';
    }

    ~rcout()
    {
        printf("%s", buff);
    }

    rcout &operator<<(char *b)
    {
        strncpy(buff+length, b, size-length);
        unsigned int i = strlen(b);
        if(i+length >= size)
        {
            buff[size-1] = '\0';
            printf("%s", buff);
            b += (size-length) -1;
            length = 0;
            return (*this) << b;
        }
        else
            length += i;
        return (*this);
    }

    rcout &operator<<(int …
Run Code Online (Sandbox Code Playgroud)

c++ performance cout

7
推荐指数
2
解决办法
9100
查看次数

Windows以二进制模式管道

我在windows中编写了一个程序,它将播放通过stdin发送给它的二进制音频,我称之为aplay(就像linux程序一样).然后我写了一个单独的程序如下

FILE * f = popen("aplay.exe", "wb");
FILE * song = fopen("C:/Users/Ray/Dropbox/DJ Automica 2/Debug/raymonster 5.wav", "rb");
while(1)
{
    byte buff[4096];
    fread(buff, 4, 1024, song);
    fwrite(buff, 4, 1024, f);
}
Run Code Online (Sandbox Code Playgroud)

由于某种原因,管道似乎没有在二进制模式下工作,因为音频全部搞砸了.如果我改变我的aplay以在文本模式下单独打开wave文件,它听起来就像我通过管道一样,如果我以二进制模式打开波形文件它会完美播放.有谁知道我怎么解决这个问题?

c windows winapi pipe popen

5
推荐指数
1
解决办法
1668
查看次数

C++在预处理器#if中的sizeof()比较中抛出编译错误

我有这个不能编译与Visual Studio的错误"致命错误C1017:无效的整数常量表达式".我该怎么做?

template <class B>
A *Create()
{
  #if sizeof(B) > sizeof(A)
  #error sizeof(B) > sizeof(A)!
  #endif
  ...
}
Run Code Online (Sandbox Code Playgroud)

c++ sizeof c-preprocessor

4
推荐指数
5
解决办法
4564
查看次数

标签 统计

c++ ×2

c ×1

c-preprocessor ×1

cout ×1

performance ×1

pipe ×1

popen ×1

sizeof ×1

winapi ×1

windows ×1