แปลง Source code ภาษา c++ ให้เป็น html

โปรแกรม cpphtml ใช้แปลง source code ภาษา c ให้เป็นไฟล์ html ได้ง่ายๆ ด้วยการพิมพ์คำสั่งเดียว

เช่น มีไฟล์ hello.cpp ดังรูปด้านล่าง

สามารถแปลงให้เป็นไฟล์ html ได้ดังนี้

cpphtml hello.cpp > hello_cpp.html

 

Download

cpphtml 1.0.0.0

 

Note: Mike Finnegan ได้เผยแพร่โปรแกรม cpphtml ไว้ที่ codeproject.com ในชื่อเรื่อง A C++ to HTML conversion utility ซึ่งผมเห็นว่าโปรแกรมนี้มีประโยชน์ เลยนำมาแนะนำ

Linked List Class

#include <iostream>

using namespace std;

class linklist
{
private:

struct node
{
int data;
node *link;
}*p;

public:

linklist();
void append( int num );
void add_as_first( int num );
void addafter( int c, int num );
void del( int num );
void display();
int count();
~linklist();
};

linklist::linklist()
{
p=NULL;
}

void linklist::append(int num)
{
node *q,*t;

if( p == NULL )
{
p = new node;
p->data = num;
p->link = NULL;
}
else
{
q = p;
while( q->link != NULL )
q = q->link;

t = new node;
t->data = num;
t->link = NULL;
q->link = t;
}
}

void linklist::add_as_first(int num)
{
node *q;

q = new node;
q->data = num;
q->link = p;
p = q;
}

void linklist::addafter( int c, int num)
{
node *q,*t;
int i;
for(i=0,q=p;i<c;i++)
{
q = q->link;
if( q == NULL )
{
cout<<“\nThere are less than “<<c<<” elements.”;
return;
}
}

t = new node;
t->data = num;
t->link = q->link;
q->link = t;
}

void linklist::del( int num )
{
node *q,*r;
q = p;
if( q->data == num )
{
p = q->link;
delete q;
return;
}

r = q;
while( q!=NULL )
{
if( q->data == num )
{
r->link = q->link;
delete q;
return;
}

r = q;
q = q->link;
}
cout<<“\nElement “<<num<<” not Found.”;
}

void linklist::display()
{
node *q;
cout<<endl;

for( q = p ; q != NULL ; q = q->link )
cout<<endl<<q->data;

}

int linklist::count()
{
node *q;
int c=0;
for( q=p ; q != NULL ; q = q->link )
c++;

return c;
}

linklist::~linklist()
{
node *q;
if( p == NULL )
return;

while( p != NULL )
{
q = p->link;
delete p;
p = q;
}
}

int main()
{
linklist ll;
cout<<“No. of elements = “<<ll.count();
ll.append(12);
ll.append(13);
ll.append(23);
ll.append(43);
ll.append(44);
ll.append(50);

ll.add_as_first(2);
ll.add_as_first(1);

ll.addafter(3,333);
ll.addafter(6,666);

ll.display();
cout<<“\nNo. of elements = “<<ll.count();

ll.del(333);
ll.del(12);
ll.del(98);
cout<<“\nNo. of elements = “<<ll.count();
return 0;
}
ที่มา: dreamincode.net/
เพิ่มเติม: How to create Linked list using C/C++

CSharp using C++ DLL

ในบทความนี้เป็นการใช้ C# เรียกใช้ DLL ที่เขียนจากภาษา C++

1. สร้างโปรเจ็กส์ C# เพื่อใช้งาน Dll ชื่อ CSConsole เป็นแบบ Console Application

2. สร้างโปรเจ็กส์ C# เพื่อใช้งาน Dll ชื่อ CSWinForm เป็นแบบ Windows Forms Application

เพิ่ม Code

using System;

เพิ่ม Code

using System;

ที่มา: Platform Invoke Tutorial

 

C++ Dll Win32 Console Project

1. สร้างโปรเจ็กส์ C++ แบบ Dll ชื่อ CDll เป็นแบบ Win32 Console Application > Dll

2. สร้างโปรเจ็กส์ C++ เพื่อใช้งาน Dll ชื่อ WinConsole เป็นแบบ Win32 Console Application > Console Application

เพิ่ม Code

เพิ่ม Code

ให้โปรเจ็กส์ WinConsole ทำการ Add reference project ไปที่โปรเจ็กส์ CDLL

ที่มา: Creation of a Simple DLLWalkthrough: Creating and Using a Dynamic Link Library

How to mix C and C++ ใน VC2005

เมื่อนำ code ภาษา c (ไฟล์ .c) มารัน อยู่ใน Project เดียวกันกับ .cpp แล้วเกิด Error ดังนี้
/Ycstdafx.h command-line option was not found in the source file
ให้แก้ไขด้วยการเพิ่ม #include “stdafx.h” ในไฟล์ .c
จากนั้นไปที่ Project > Properties > Configuration Properties > C/C++ > Precomplied Headers > Create/Use Precomplied Header
ให้เลือก Use Precomplied Header (/Yu)
เป็นอันเสร็จ

VS2010: IntelliSense: #error directive: Please use the /MD switch for _AFXDLL builds

สร้าง Project ใหม่แบบ MFC และเลือก Shared Library พอสั่งรันแล้วเกิด Error ดังนี้

IntelliSense: #error directive: Please use the /MD switch for _AFXDLL builds

ให้แก้ไขโดยคลิกขวาที่ Project เลือก properties > Configuration Properties > C/C++ > Code Generation

จากนั้นให้ดูที่ Runtime Libraryจะมีค่า default เป็น Multi-threaded Debug DLL (/MDd) แต่ไม่ใช่ตัวหนา

จากนั้นให้เปลี่ยนเป็นค่าอื่นก่อน แล้วเลือกกลับมาเป็น Runtime Library ให้เป็น Multi-threaded Debug DLL (/MDd) อีกครั้ง จะสังเกตุเห็นได้ว่า คำว่า Multi-threaded Debug DLL (/MDd) กลายเป็นตัวหนาแล้ว เป็นอันเสร็จ

อันนี้เข้าใจว่าเป็น Bug ของ VC 2010

vs2010

ที่มา: connect.microsoft.combasharatspace.blogspot.com