我刚刚开始在UNIX中使用套接字编程,我正在阅读套接字系统调用的手册页.我对AF_LOCAL参数及其使用时有点困惑.手册只是说当地的沟通.AF_INET格式不适用于本地通信吗?
我正在尝试编写一个小程序来查找打开文件流的缓冲区大小.在搜索了一下之后,我找到了__fbufsize()函数.这是我写的代码:
#include <stdio.h>
#include <stdio_ext.h>
void main() {
FILE *f;
int bufsize;
f = fopen("test.txt","wb");
if (f == NULL) {
perror("fopen failed\n");
return;
}
bufsize = __fbufsize(f);
printf("The buffer size is %d\n",bufsize);
return;
}
Run Code Online (Sandbox Code Playgroud)
我得到缓冲区大小为零.我有点困惑为什么会发生这种情况.默认情况下不应该缓冲流吗?如果在调用fbufsize之前将setvbuf与_IOFBF一起使用,则会得到一个非零值.
我正在尝试理解C++ 11中的移动语义,并且我编写了一小段代码来检查在创建对象时调用哪些构造函数.
这是代码:
#include <iostream>
using namespace std;
class Bar
{
public:
int b;
Bar();
Bar(const Bar&);
~Bar();
};
class Foo
{
public:
int d;
Bar* b;
Foo();
Foo(const Foo&);
Foo(Foo&& other);
~Foo();
Foo& operator = (Foo);
};
Foo test();
Foo::Foo()
{
cout << "Default ctr of foo called\n";
b = new Bar();
}
Foo::~Foo()
{
delete b;
}
Foo::Foo(const Foo& other)
{
cout << "Copy ctr of foo called\n";
d = other.d;
b = new Bar();
b->b = other.b->b; …Run Code Online (Sandbox Code Playgroud)