FILE *freopen(const char *path, const char *mode, FILE *stream);
以下是簡單小範例
#include <iostream>
int main() {
freopen("test.txt", "w", stdout);
std::cout << "Hello freopen()" << std::endl;
return 0;
}執行時,便不會看到任何輸出,而是會出現在test.txt檔案裡。
#include <iostream>
int main() {
freopen("test.txt", "w", stdout);
std::cout << "Hello freopen()" << std::endl;
return 0;
}STDMETHODIMP CMyATL::Add(LONG lNum1, LONG lNum2, LONG * plResult)
{
*plResult = lNum1 + lNum2;
return S_OK;
}#include "SimpleATL_i.h"
#include <iostream>
using namespace std;
void main(void)
{
HRESULT hr;
IMyATL *pIMyATL;
hr = CoInitialize(NULL);
if(SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_MyATL, NULL, CLSCTX_INPROC_SERVER, IID_IMyATL, (void**) &pIMyATL);
if(SUCCEEDED(hr))
{
long lResult;
hr = pIMyATL->Add(5, 10, &lResult);
cout << "5 + 10 = " << lResult << endl;
hr = pIMyATL->Release();
}
else
cout << "CoCreateInstance Failed." << endl;
}
CoUninitialize();
}
sock = socket(AF_INET, SOCK_STREAM, 0);
int on = 1;
int status = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));
if (status == -1)
perror("setsockopt() error");
#ifndef _ADD_INT_H_
#define _ADD_INT_H_
#define DLLExport __declspec( dllexport )
extern "C"
{
DLLExport int Add(int a, int b);
}
#endif#include "AddInt.h"
int Add(int a, int b) {
return a + b;
}#include <iostream>
#include "AddInt.h"
int main()
{
std::cout << Add(5, 10) << std::endl;
return 0;
}#include <iostream>
#include <windows.h>
typedef int (*pfAddIntFunction)(int,int);
int main()
{
pfAddIntFunction pfAddInt ;
HINSTANCE hLibrary = LoadLibrary(L"AddInt.dll");
if(hLibrary)
{
pfAddInt = (pfAddIntFunction)GetProcAddress(hLibrary, "Add");
if(pfAddInt)
{
std::cout << pfAddInt(5, 10) << std::endl;
}
FreeLibrary(hLibrary);
}
else
{
std::cout << "Failed To Load Library" << std::endl;
}
return 0;
}
假設在NAT下的主機A為(iIP, iPort),實際對外為(eIP, ePort)
Full cone NAT: 任何主機皆可透過(eIP, ePort)送封包給A。
(Address) Restricted cone NAT:只有之前收過A送來封包的外部主機(hIP, any),才可透過(eIP, ePort)送封包給A,不限定原來溝通的Port。
Port-Restricted cone NAT :同上,但外部主機只能用之前用的Port才能送封包給A。
Symmetric NAT:同上,但A對每一個不同的(hIP, hPort),也就是IP或Port的任何一值改變,其(eIP, ePort)就會不同。
void hello();#include "hello.h"
#include <iostream>
void hello() {
std::cout << "Hello CMake!" << std::endl;
}#include "hello.h"
int main() {
hello();
return 0;
}#include "fcgi_stdio.h"
#include <stdlib.h>
int main()
{
int count = 0;
while(FCGI_Accept() >= 0) {
printf("Content-type: text/html\r\n"
"\r\n"
"<title>Hello FastCGI</title>"
"<h1>Hello FastCGI</h1>"
"Request number %d running on host <i>%s</i>\n",
++count, getenv("SERVER_NAME"));
}
return 0;
}uintptr_t _beginthread(
void( __cdecl *start_address )( void * ),
unsigned stack_size,
void *arglist
);#include <windows.h>
#include <process.h>
#include <iostream>
using namespace std;
void func1(void *);
void func2(void *);
int main()
{
_beginthread(func1, 0, NULL);
_beginthread(func2, 0, NULL);
Sleep(10000);
cout << "Main exit" << endl;
getchar();
return 0;
}
void func1(void *p)
{
for(int i = 1; i < 6; ++i)
cout << "func1 value " << i << endl;
}
void func2(void *p)
{
for(int i = 1; i < 6; ++i)
cout << "func2 value " << i << endl;
}