Sunday, October 24, 2010

Convert char array to string

Diambil dari rujukan [1]

Cara susah:

string str;
char array[] = "Hello World";
for(int i = 0; array[i] != 0; i++)
str += array[i];

Cara senang

string str;
char array[] = "Hello World";

str = array;

Rujukan:

[1] http://www.programmersheaven.com/mb/CandCPP/309708/309708/converting-char-array-to-string-type/

Split string to vector

Saya ambil dari rujukan [1]

Contoh:

string d = "Ahmad 54 34 45";

vector result;

split(d,'\t',result);


vector &split(const string &s, char delim, vector &elems) {
stringstream ss(s);
string item;
while(std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}


Rujukan:

1. http://stackoverflow.com/questions/236129/how-to-split-a-string

Convert string to double

Contoh;

string d = "23.5";

double nilai = atof(d.c_str());

Rujukan:

1. http://www.gidforums.com/t-1131.html

Friday, October 15, 2010

Convert char* (char pointer) to char array

char* nama = "Hashim";
char nama_pelajar[256];

for(int i=0;i nama_pelajar[i] = nama[i];

Tuesday, October 5, 2010

Install Adobe Flash player on Ubuntu 10.04 LTS 64 bit

Sila ke laman web youtube disini dan tengok keterangan dibawah video tersebut. (sebab bila pertama kali install ubuntu, adobe flash belum install lagi, jadi tak dapat la tonton video tersebut).

Sebagai backup saya salin cara2nya seperti dibawah:

-------------***************-------------
This tutorial will detail installing Adobe Flash 10.1 in 64bit Ubuntu 10.04 LTS. Flash 10.1 is the newest release designed with emphasis on performance via hardware acceleration. In my experience, it runs much smoother and more stable than the version available for download through the Ubuntu Software Center.

-----

Installation: (Make sure you remove any current versions of Flash before continuing)

-Navigate to http://get.adobe.com/flashplayer/ and download the tar.gz for Linux.
-Extract libflashplayer.so to your Desktop

-Navigate to your terminal and type:
- cd /home/user_name/Desktop (case sensitive, replace user_name with your username)

Then input the following 4 commands individually:
- sudo mv libflashplayer.so /usr/lib/mozilla/plugins/
- sudo nspluginwrapper -i /usr/lib/mozilla/plugins/libflashplayer.­so
- sudo ln -sf /usr/lib/nspluginwrapper/plugins/npwrapp­er.libflashplayer.so /usr/lib/mozilla/plugins/
- sudo ln -sf /usr/lib/nspluginwrapper/plugins/npwrapp­er.libflashplayer.so /usr/lib/firefox-addons/plugins/

And you're done!

-----

If you'd like to uninstall, input the following commands in your terminal:

- sudo rm /usr/lib/mozilla/plugins/libflashplayer.­so
- sudo rm /usr/lib/nspluginwrapper/plugins/npwrapp­er.libflashplayer.so
- sudo rm /usr/lib/mozilla/plugins/npwrapper.libfl­ashplayer.so
- sudo rm /usr/lib/firefox-addons/plugins/npwrappe­r.libflashplayer.so