Love?

TRY TO MAKE DREAM COME TRUE

Quảng cáo

---

Chủ Nhật, 27 tháng 12, 2009

[C#] How To: Reading and Writing Text Files

Introduction

Text files provide a common denominator format where both people and programs can read and understand. The .NET Framework includes convenience classes that make reading and writing text files very easy. The following sequence outlines the basic steps necessary to work with text files:

  1. Open the file
  2. Read/Write to the file
  3. Close the file

It's that simple. Listing 1 shows how to write text data to a file.

Writing to a Text File

Listing 1: Writing Text Data to a File: TextFileWriter.cs

using System;
using System.IO;

namespace csharp_station.howto
{
class TextFileWriter
{
static void Main(string[] args)
{
// create a writer and open the file
TextWriter tw = new StreamWriter("date.txt");

// write a line of text to the file
tw.WriteLine(DateTime.Now);

// close the stream
tw.Close();
}
}
}

This program creates a text file when it runs. In the directory where the executable program is located, you'll find a file named date.txt. If you view the contents of this file, you'll see the following textual representation of the date and time when the program last ran:

2/15/2002 8:54:51 PM

The first task in Listing 1 is to open the file. This happens by instantiating a StreamWriter class, which returns an object of type TextWriter. The result could have also been assigned to a StreamWriter instance. The StreamWriter was called with a single parameter, indicating the name of the file to open. If this file doesn't exist, the StreamWriter will create it. The StreamWriter also has 6 other constructor overloads that permit you to specify the file in different ways, buffer info, and text encoding. Here's the line that opens the date.txt file:

TextWriter tw = new StreamWriter("date.txt");

Using the TextWriter instance, tw, you can write text info to the file. The example writes the text for the current date and time, using the static Now property of the DateTime class. Here's the line from the code:

tw.WriteLine(DateTime.Now);

When you're done writing to the file, be sure to close it as follows:

tw.Close();

Reading From a Text File

Listing 2 shows how to read from a text file:

Listing 2: Reading Text Data from a File: TextFileReader.cs

using System;
using System.IO;

namespace csharp_station.howto
{
class TextFileReader
{
static void Main(string[] args)
{
// create reader & open file
Textreader tr = new StreamReader("date.txt");

// read a line of text
Console.WriteLine(tr.ReadLine());

// close the stream
tr.Close();
}
}
}

In Listing 2, the text file is opened in a manner similar to the method used in Listing 1, except it uses a StreamReader class constructor to create an instance of a Textreader. The StreamReader class includes additional overloads that allow you to specify the file in different ways, text format encoding, and buffer info. This program opens the date.txt file, which should be in the same directory as the executable file:

Textreader tr = new StreamReader("date.txt");

Within a Console.WriteLine statement, the program reads a line of text from the file, using the ReadLine() method of the Textreader instance. The Textreader class also includes methods that allow you to invoke the Read() method to read one or more character or use the Peek() method to see what the next character is without pulling it from the stream. Here's the code that reads an entire line from the text file:

Console.WriteLine(tr.ReadLine());

When done reading, you should close the file as follows:

tr.Close();

Summary

This article showed how to write text to a file and read it back out. For more details on additional methods, consult the .NET Frameworks reference on the StreamWriter, StreamReader, TextWriter, and Textreader classes.

theo C# station

Thứ Bảy, 26 tháng 12, 2009

Hỏi và đáp

Hỏi: Em là mối tình thứ mấy của anh?

Đáp: Không phải là đầu tiên, chưa chắc là cuối cùng, và dĩ nhiên không phải là “duy nhất”. Nhưng là mãi mãi.

H: Tại sao anh yêu em?

Đ: Nếu biết tại sao thì anh đã biết cách ngừng yêu em rồi.

H: Anh có phải là người chung thủy không?

Đ: Không. Nếu chung thủy anh đã không phản bội lại người phụ nữ từng là duy nhất của đời anh để quay sang yêu em.

H: (nghẹn ngào)

Đ: Mẹ anh.

H: Nếu em không xinh/ giỏi…. như bây giờ liệu anh có yêu em không?

Đ: Không. Lúc đó em đâu còn là em nữa.

H: Em sẽ nhận lời yêu anh nếu anh dám nhảy xuống hồ này vì em?

Đ: Không. Anh đâu có muốn em yêu một thằng ngu.

H: Không biết sau này anh hay em chết trước nhỉ?!

Đ: Hy vọng là em. Anh không muốn em phải chịu đựng cảm giác đau khổ khi phải sống một mình trên đời này.

H: Bạn bè anh có ủng hộ chúng ta quen nhau không?

Đ: Dĩ nhiên là không. Yêu em, anh không còn tâm trí và thời gian để dành cho bạn bè nữa.

H: Trước đây anh có từng nghĩ sẽ yêu một người như em không?

Đ: Không. Anh thậm chí không dám nghĩ đến điều cao xa như thế.

H: Anh ghét đi shopping với em lắm đúng không?

Đ: Ừ, rất ghét. Cùng một quãng thời gian đó, nếu ta vào quán café, anh sẽ nói được một ngàn lần câu “anh yêu em”.

H: Khi nói “anh yêu em”, anh có lừa dối em không?

Đ: Có. Thật ra là “anh yêu em rất nhiều”
sưu tầm

Visual Prolog 7.1 (Trí tuệ nhân tạo)

Visual Prolog

Visual Prolog is a logical programming language that counts PDC Prolog and Turbo Prolog as predecessors.

The goal of Visual Prolog is to support industrial strength programming of complex knowledge emphasized problems.

Today Visual Prolog is a very powerful and safe programming language combining the very best features of logical, functional and object-oriented programming paradigms in a consistent and elegant way.

Visual Prolog features:

  • logical programming concepts (backtracking, pattern matching);
  • algebraic data types;
  • a unique object system;
  • multi-threading (supported in the Commercial Edition);
  • parametric polymorphism
  • unicode support;
  • automatic memory management (garbage collection);
  • much more.

Visual Prolog is a complete programming environment with:

With Visual Prolog you can build applications for the Microsoft Windows 32 platform. It supports advanced client-server and three-tier solutions. Visual Prolog is especially well suited for dealing with complex knowledge.

By utilizing a powerful object system you are able to architect your application very rigidly and at the same time benefiting from very loose coupling. This will enable you to reduce development and even more maintenance cost.


LINK DOWNLOAD


Kiến thức phải biết về .NET

1. Sự khác nhau giữa các lớp Trace và Debug?

- Trace dùng để theo dõi các hành động xảy ra. Nó hoạt động trong các đóng gói cả Debug lẫn Release. Trace là khả năng của chương trình tự đưa ra các thông tin về hành động của mình.

- Debug dùng để tìm và sửa các lỗi trong chương trình. Nó chỉ hoạt động trong đóng gói Debug.

2. Sự khác nhau giữa static readonly và const?

- Static readonly là hằng số được khởi tạo khi thực thi chương trình.

- Const là hằng số được khởi tạo khi biên dịch chương trình.

3. Sự khác nhau giữa String và StringBuilder?

- String là lớp không thay đổi. Mọi phương thức sẽ tạo ra một biến String mới.

- StringBuilder là lớp thay đổi. Các phương thức của biến sẽ ảnh hưởng đến đến biến StringBuilder hiện tại.

4. Sự khác nhau giữa “” và String.Empty?

- “” sẽ tạo thêm 1 đối tượng khi làm việc với nó (so sánh, copy…)

- String.Empty không tạo đối tượng nào cả. String.Emtpy nằm trong mscorlib.

Khi kiểm tra 1 String có rỗng hay không nên dùng String.Length == 0 để có tốc độ nhanh nhất.

5. Có thể gán một struct bằng null hay không?

- Có thể nếu bạn lập trình với C# 2.0. Ví dụ: int? var = 1; var = null;

6. Sự khác nhau giữa == và phương thức Equals?

- == so sánh theo kiểu giá trị.

- Equals so sánh theo kiểu tham chiếu.

7. Sự khác nhau giữa throw và throw ex?

- throw đế đưa lại toàn bộ các tầng theo dõi của lỗi ra.

- throw ex bỏ bớt các tầng theo dõi bên dưới phương thức gọi throw ex.

8. Connection Pooling dùng để làm gì?

- Cho phép tăng tốc độ của các ứng dụng Web bằng cách dùng lại các kết nối thay vì tạo các kết nối mới với mỗi yêu cầu.

9. .NET có hỗ trợ thừa kế từ nhiều lớp hay không (multiple inheritance)? Tại sao?

- Không. Vì sẽ không hiểu được khi gọi 1 phương thức mà 2 lớp cha cùng override nó.

10. Sự khác nhau giữa abstract class và interface?

- Có thể thừa kế từ nhiều interface nhưng chỉ có thể thừa kế từ 1 abstract class.

- Có thể viết sẵn các thực thi trong Abstract class, nhưng interface thì không.

- Interface dùng để gom các hành động cần được hiện thực , các khả năng của một đối tượng (ví dụ con người và xe cộ cùng có khả năng đi lại, nhưng con người không cùng tính chất với xe cộ), còn abstract class cho các lớp thừa kế cùng 1 loại, tính chất hay trạng thái (ví dụ đàn ông, phụ nữ, trẻ con, người già đều là con người).

- Abstract class có tốc độ thực thi nhanh hơn interface.

- Thêm 1 tính năng mới vào interface sẽ phá vỡ toàn bộ các lớp hiện thực, còn abstract thì không.

11. Hàm GetHasCode() trong System.Object dùng để làm gì?

- Trả về giá trị của một đối tượng. Chú ý hàm này mặc định không trả về giá trị duy nhất hoặc không đổi. Hàm này có thể override.

12. Sự khác nhau giữa DataSet và DataReader?
- DataSet có thể đọc và ghi trong khi DataReader chỉ có thể đọc.
- DataSet có thể chứa nhiều bảng còn DataReader chỉ có thể chứa 1 bảng.
- DataSet làm việc ở chế độ không kết nối còn DataReader làm việc ở chế độ kết nối.
- DataSet có thể di chuyển tới và trở lại còn DataReader thì chỉ có thể di chuyển tới.
- DataSet truy cập chậm hơn DataReader.

13. Sự khác nhau giữa các phuơng thức Copy và Clone?
- Clone chỉ copy cấu trúc trong khi Copy copy cả cấu trúc lẫn dữ liệu.

14. Sự khác nhau giữa Dispose, Destructor và Finalize?
- Destructor sẽ được chuyển thành Finalize khi biên dịch. Hàm Finalize được gọi bởi .NET Runtime và chúng ta không thể đoàn được nó được gọi khi nào, nhưng nó chắc chắn sẽ được gọi.
- Dispose sẽ giải phóng bộ nhớ ngay khi nó được gọi. Lưu ý nếu lớp nào override Dispose mà quên gọi thì các đối tượng sẽ không tự giải phóng bộ nhớ.

15. Serialization là gì?
- Là sự chuyển chuyển đối tượng thành 1 luồng các bytes.

16. Sự khác nhau giữa XmlSerializer, BinaryFormatter và SoapFormatter?
- XmlSerializer dùng cho dịch vụ Web.
- BinaryFormatter/SoapFormatter dùng cho Remoting.
- SoapFormatter dùng để tuần tự hóa 1 đối tượng thành SOAP.
- BinaryFormatter dùng để tuần tự hóa 1 đối tượng thành dạng nhị phân.
- XmlSerializer chỉ chuyển đổi các tính chất public còn BinaryFormatter/SoapFormatter chuyển đổi cả public lẫn private.

17. Sự khác nhau giữa overriding và shadowing?
- Overriding cung cấp sự hiện thực mới của 1 hàm ở lớp thừa kế nhưng không thay đổi số biến, kiểu trả về, mức truy cập còn shadowing thì có thể thay đổi (từ khóa new trong C#).

18. Sự khác nhau giữa class, object, struct và interface?
- Class là cấu trúc dữ liệu định nghĩa bởi người dùng chứa các tính chất và phương thức. Object là một trường hợp cụ thể của class. Class không chiếm bộ nhớ, còn Object được tạo trong bộ nhớ.
- Class là cấu trúc dữ liệu định nghĩa bởi người dùng chứa các tính chất và phương thức. Struct là kiểu giá trị được lưu trữ trong stack còn class là kiểu tham chiếu (các object) được lưu trữ trong heap.
- Khi struct được khởi tạo không bằng hàm khởi tạo người dùng sẽ phải khởi tạo tất cả các Fields trước khi sử dụng nó.

- Interface là một hợp đồng gồm một nhóm các phương thức cần được hiện thực.

19. Sự khác nhau giữa Property và Field?
- Property dùng để quản lý sự truy cập đến Field. Dùng Property để đảm bảo Field không bị gán các giá trị không hợp lệ.

20. Sự khác nhau giữa static Method, static constructor với method và constructor thông thường?
- Static method có thể gọi mà không cần khởi tạo biến. Static constructor chỉ được gọi đúng một lần khi object đầu tiên được khởi tạo.

21. Các biến tĩnh và chỉ dẫn chương trình được lưu ở đâu?
- Ở 1 vùng bộ nhớ đặc biệt gọi là Permanent Storage area.

22. Sự khác nhau giữa stack và heap?
- Stack và heap là các vùng bộ nhớ. Heap nằm giữa stack và Permanent Storage area, và độ lớn có thể thay đổi khi thực thi chương trình.

23. Sự khác nhau giữa Boxing and Un-Boxing?
- Boxing là chuyển đổi kiểu giá trị thành kiểu tham chiếu. Un-Boxing ngược lại.

24. Mục đích của thừa kế (inheritance)?
- Để tái sử dụng.

25. Mục đích của đa hình (poymophism)?
- Một hành động có thể xảy ra theo nhiều cách khác nhau.

26. Sự khác nhau giữa Compile Time Polymorphism và Run Time Polymorphism?
- Compile Time Polymorphism - ví dụ Overloading, một hàm có thể có nhiều cách biểu diễn.
- Run Time Polymorphism - ví dụ Overriding, một hàm có thể có nhiều cách xử lý.

27. Sự khác nhau giữa delegate và event?
- delegate là một lớp (class) đại diện cho hàm con trỏ kiểu an toàn hoặc hàm gọi (call backs) chỉ đến địa chỉ tham chiếu của một (hay nhiều) hàm. Con trỏ hàm chứa trong delegate được gắn vào một đối tượng đích (target) và khi delegate được kích hoạt phương thức sẽ được gọi ở đối tượng đích. Sự hữu ích của delegate không nằm ở chỗ giữ địa chỉ tham chiếu của các hàm mà để định nghĩa và dùng các tên hàm khi runtime thay vì compile time.
- event cho phép xác định một delegate sẽ được gọi khi có sự xuất hiện của “sự kiện” nào đó. event là một modifier trong khi delegate là một lớp. event cho phép một delegate được khai báo trong interface.

29. AppDomain là gì?
- Là một miền riêng biệt lưu trữ code và dữ liệu cho một application. Một process có thể chứa nhiều AppDomains.
Khi bạn copy một DLL mới vào bin, ASP.NET runtime sẽ không thể đưa nó vào một AppDomain đang chạy.Nó sẽ dừng từ từ AppDomain cũ (dừng hẳn khi nó dừng tất cả các requests) và mở một AppDomain mới.

30. Sự khác nhau giữa publish và published interfaces.
- publish interface là interface mà bạn có thể sửa tất cả những code nào dùng nó còn published interface là interface mà bạn không thể sửa code dùng nó.

31. Sự khác nhau giữa try{}catch{} và try{}catch{Exception ex}?
- Chúng giống hệt nhau.

32. Sự khác nhau giữa 1/0; và try{1/0;} catch {throw;}
- Chúng giống hệt nhau. Vì vậy nếu không xử lý catch thì đừng catch.

33. Sự khác nhau giữa Remoting và Web service?
- Web service không có trạng thái, không cần biết đến client chỉ sử dụng trên HTTP, hỗ trợ không đồng nhất các môi trường, tốc độ chậm hơn Remoting.
- Remoting có trạng thái kết nối, hỗ trợ nhiều giao thức hơn HTTP, TCP…, đòi hỏi môi trường đồng nhất, tốc độ nhanh đặc biệt khi dùng trên TCP.

34. Sự khác nhau giữa error và exception?
- Error là lỗi của chương trình còn exception là lỗi chương trình được phát hiện và có thể xử lý.

35. Sự khác nhau giữa Procedure và OO?
- Procedure gồm các hàm và các biến, tất cả các hàm đều có thể truy cập đến tất cả các biến. Không thể quản lý các biến.
- OO gom hàm và biến vào các đơn vị object. Các hàm và biến được quản lý trong nội bộ object. Các object tương tác với nhau thông qua các interfaces.

36. CLR, CTS, CLS, MSIL, JIT, PE, GAC là viết tắt của những gì?
- Là Common Language Runtime: môi trường để chạy các ứng dụng .NET
- Là Common Type System: mô tả các loại dữ liệu trong .NET.
- Là Common Language Specification: mô tả các quy định và chuẩn cho các ngôn ngữ trong .NET
- Là Microsoft Intermediate Language: ngôn ngữ thông dịch của .NET.
- Là Just In Time: trình biên dịch MSIL thành mã máy.
- Là Portable Executable: file chứa MSIL.
- Là Global Assembly Cache: nơi lưu trữ các Asembly dùng chung.

37. Các mâu thuẫn giữa OO và RDBMS?
- Cấu trúc cấp bậc trong OO có thể là vô tận trong khi ở RDBMS chỉ có 4 loại table, row, column, cell.
- Các đối tượng trong OO bản thân là phân biệt trong khi trong RDBMS cần phải có primary-key.
- Các đối tượng trong OO có thể tham chiếu đến nhau rất đơn giản nhưng trong RDBMS thì phức tạp thông qua JOIN
- Sự thừa kế trong OO là đơn giản trong khi trong RDBMS hầu như không có khái niệm đó. Một bảng cần chứa tất cả các tính chất, có khi là thừa.
- Các đối tượng trong OO có thể có các hành động tác động đến tối tương khác.trong RDBMS thì phức tạp thông qua TRIGGER
- Khả năng truy cập trong OO là hạn chế trong khi ở RDBMS là không giới hạn.

38. Sự khác nhau giữa Response.Redirect và Server.Transfer.
- Response.Redirect đơn thuần là chuyển bạn đến một trang mới giống như bạn gõ địa chỉ trang đó trên browser và request đến server.
- Server.Transfer cũng chuyển bạn đến trang mới nhưng ở phía server, làm giảm request đến server, giữa nguyên URL của bạn và có thể chuyển cả các query string và biến trên form đên địa chỉ mới, chỉ thực hiện giữa các trang trên cùng 1 host.

39. Vai trò của ASPX page và ASPX page code-behind trong MVC.
- ASPX page là View còn ASPX page code-behind là Controller.

40. Làm thế nào để try/catch trên toàn bộ 1 ASPX page.
- Dùng Page_Error event.

41. Sự khác nhau giữa Cohesion và Coupling
- Cohesion là sự liên kết giữa các thành phần trong một module. Một thiết kế tốt nên có sự liên kết giữa các thành phần thật chặt chẽ.
- Coupling là sự kết nối giữa các module với nhau. Một thiết kế tốt nên có sự kết nối thật lỏng lẽo giữa các module.

42. Refractoring là gì?
- Là sự thiết kế lại cấu trúc của code bằng cách thay đổi cấu trúc bên trong mà không ảnh hưởng đến các hành vi bên ngoài (interface) của đoạn code (module, system) đó.

43. Phân biệt HttpApplication, Session, ViewSate và HttpContext?
- Cả 4 thành phần trên đều dùng để lưu dữ liệu của một Web Application.
- HttpApplication có tác dụng trong toàn bộ quá trình thực thi của Web Application.
- Session có tác dụng trong 1 lần ghé thăm (visit) của người dùng. Nó kết thúc khi gặp timeout.
- ViewState có tác dụng trong trong 1 trang web.
- HttpContext có tác dụng trong 1 request.
Theo Internet or Some Document

Thứ Sáu, 25 tháng 12, 2009

Định nghĩa tình yêu

LỊCH SỬ : Tình yêu là một cuộc cách mạng giải phóng chủ nghĩa độc thân .

ĐỊA LÝ : Tình yêu là một trận động đất trong tâm hồn và trái tim chính là " núi lửa " .

HÓA HỌC : Tình yêu là một phản ứng hóa học sinh ra a xít .

VẬT LÝ : Tình yêu là một lực hút mạnh hơn cả lực hút của trái đất .

TOÁN HỌC : Tình yêu là một phép trừ của túi tiền , phép chia của trái tim , phép nhân của nhân loại và là phép cộng của mọi rắc rối .

VĂN HỌC : Tình yêu là quyển sách dày mà đọc từ trang đầu đến trang cuối ta vẫn không hiểu gì cả ....

ẨM THỰC : Tình yêu là một lít rượu hoà chung với hai lít dấm .

TÂM LÝ HỌC : Tình yêu là một cuộc rượt đuổi mà chàng rượt theo nàng cho đến khi nàng bắt được chàng.

Y HỌC : Tình yêu là sự tranh đấu với tử thần , giữa cái sống và cái chết .

ÂM NHẠC : Tình yêu là điệp khúc hay nhưng hát măi cũng chán ......,.,,,

MẦM NON : Tình yêu giống như một đứa con nít , khi bỏ đói thì khóc và giận lẫy , khi quá no thì bội thực và tống hết mọi thứ ra ngoài .

TÂM THẦN HỌC : Tình yêu giống như bệnh tâm thần . Người đang yêu nhìn thấy, nghe thấy những điều mà người bình thường không nghe thấy. Họ cười , khóc , giận , thương , buồn , vui .... vô cớ mà vẫn cho rằng mình rất tỉnh táo
..................................................

Thứ Năm, 24 tháng 12, 2009

File I/O in C++ : part 2 of 2

Checking the I/O status - Flags

I won’t be explaining what flags are. But even if you don’t know about them, reading this chapter to the end may give you some idea, and I believe you will understand the theory. Even so, if you don’t know about the flags in C++, I recommend you to find some reading on this subject.
Okay, let’s start!

The Input/Output system in C++, holds information about the result of every I/O operation. The current status is kept in an object from type io_state, which is an enumerated type (just like open_mode) that has the following values:

godbitNo errors.
eofbitEnd of file has been reached
failbitNon-fatal I/O error
badbitFatal I/O error

There are two ways, to receive information about the I/O status. One of them is by calling the function rdstate(). It returns the current status of the error-flags (the above mentioned). For example, the rdstate() function will return goodbit if there were no errors.
The other way to check the I/O status is by using any of the following function:

bool bad();
bool eof(); //remember this one? "Read until the end of the file has been reached!"
bool fail(); //and this one, too… Check if the file opening was successfull
bool good();

The function bad() returns true, if the badbit flag is up. The fail() function returns true if the failbit flag is up. The good() function returns true if there were no errors (the goodbit flag is up). And the eof() function returns true if the end of the file has been reached (the eofbit flag is up).
If an error occurred, you will have to clear it if you want your program to continue properly. To do so, use the clear() function, which takes one parameter. The parameter should be the flag you want to put to be the current status. If you want your program to continue “on clear”, just put ios::goodbit as parameter. But notice that the clear() function can take any flag as parameter. You will see that in the code examples bellow.

I will now show you some example code that will confirm your knowledge.

Example 1: Simple status check

//Replace FileStream with the name of the file stream handle
if(FileStream.rdstate() == ios::eofbit)
cout << "End of file!\n";
if(FileStream.rdstate() == ios::badbit)
cout << "Fatal I/O error!\n";
if(FileStream.rdstate() == ios::failbit)
cout << "Non-fatal I/O error!\n";
if(FileStream.rdstate() == ios::goodbit)
cout << "No errors!\n";

Example 2: The clear() function

#include


void main()
{
ofstream File1("file2.txt"); //create file2.txt
File1.close();
//this bellow, will return error, because I use the ios::noreplace
//open_mode, which returns error if the file already exists.
ofstream Test("file2.txt",ios::noreplace);
//The error that the last line returned is ios::failbit, so let's show it
if(Test.rdstate() == ios::failbit)
cout << "Error...!\n";
Test.clear(ios::goodbit); //set the current status to ios::goodbit
if(Test.rdstate() == ios::goodbit) //check if it was set correctly
cout << "Fine!\n";
Test.clear(ios::eofbit); //set it to ios::eofbit. Useless.
if(Test.rdstate() == ios::eofbit) //and check again if it is this flag indeed
cout << "EOF!\n";
Test.close();
}

Instead using flags, you can use a function that actually does the same- checks if specific flag is up. The functions were mentioned before, so I won’t mention them again. If you are not sure how to use them, just check out the place of the tutorial, where I showed few ways to check if file opening was successful or not. There, I used the fail() function.

Dealing with Binary files

Although, the files with formatted text (all that I talked about so far) are very useful, sometimes you may need to work with unformatted files- binary files. They have the same look as your program itself, and it is much different from what comes after using the <<>> operators. The functions that give you the possibility to write/read unformatted files are get() and put(). To read a byte, you can use get() and to write a byte, use put(). You should remember of get()… I have already used it before. You wonder why even using it, the file looks formatted? Well, it is because I used the <<>> operators, I suppose.
get() and put() both take one parameter- a char variable or character.
If you want to read/write whole blocks of data, then you can use the read() and write() functions. Their prototypes are:

istream &read(char *buf, streamsize num);
ostream &write(const char *buf, streamsize num);

For the read() function, buf should be an array of chars, where the read block of data will be put. For the write() function, buf is an array of chars, where is the data you want to save in the file. For the both functions, num is a number, that defines the amount of data (in symbols) to be read/written.

If you reach the end of the file, before you have read “num” symbols, you can see how many symbols were read by calling the function gcount(). This function returns the number of read symbols for the last unformatted input operation.
And before going to the code examples, I have to add, that if you want to open a file for binary read/write, you should pass ios::binary as an open mode.

Now, let me give you some code examples, so that you can see how stuff works.

Example 1: Using get() and put()

#include


void main()
{
fstream File("test_file.txt",ios::out | ios::in | ios::binary);
char ch;
ch='o';
File.put(ch); //put the content of ch to the file
File.seekg(ios::beg); //go to the beginning of the file
File.get(ch); //read one character
cout << ch << endl; //display it
File.close();
}

Example 2: Using read() and write()

#include
#include


void main()
{
fstream File("test_file.txt",ios::out | ios::in | ios::binary);
char arr[13];
strcpy(arr,”Hello World!”); //put Hello World! into the array
File.write(arr,5); //put the first 5 symbols into the file- “Hello”
File.seekg(ios::beg); //go to the beginning of the file
static char read_array[10]; //I will put the read data, here
File.read(read_array,3); //read the first 3 symbols- “Hel”
cout << read_array << endl; //display them
File.close();
}

Some useful functions

tellg() - Retunrs an int type, that shows the current position of the inside-pointer. This one works only when you read a file. Example:

#include


void main()
{
//if we have "Hello" in test_file.txt
ifstream File("test_file.txt");
char arr[10];
File.read(arr,10);
//this should return 5, as Hello is 5 characters long
cout << File.tellg() << endl;
File.close();
}

tellp() - The same as tellg() but used when we write in a file. To summarize: when we read a file, and we want to get the current position of the inside-pointer, we should use tellg(). When we write in a file, and we want to get the current position of the inside-pointer, we should use tellp(). I won’t show a code example for tellp() as it works absolutely the same way as tellg().

seekp() - Remember seekg()? I used it, when I was reading a file, and I wanted to go to specified position. seekp() is the same, but it is used when you write in a file. For example, if I read a file, and I want to get 3 characters back from the current position, I should call FileHandle.seekg(-3). But if I write in a file, and for example, I want to overwrite the last 5 characters, I have to go back 5 characters. Then, I should use FileHandle.seekp(-5).

ignore() - Used when reading a file. If you want to ignore certain amount of characters, just use this function. In fact, you can use seekg() instead, but the ignore() function has one advantage- you can specify a delimiter rule, where the ignore() function will stop. The prototype is:

istream& ignore( int nCount, delimiter );

Where nCount is the amount of characters to be ignored and delimiter is what its name says. It can be EOF if you want to stop at the end of the file. This way, this function is the same as seekg(). But it can also be ‘\n’ for example, which will stop on the first new line. Here is example:

#include

void main()
{
//if we have "Hello World" in test_file.txt
ifstream File("test_file.txt");
static char arr[10];
//stop on the 6th symbol, if you don’t meet “l”
//in case you meet “l”- stop there
File.ignore(6,’l');
File.read(arr,10);
cout << arr << endl; //it should display "lo World!"
File.close();
}

getline() - I have already mentioned about this one. But there is something I didn’t tell you about. This function can be used to read line-by-line, but it can be set to stop reading if it met a certain symbol. Here is how you should pass the parameters to it:

getline(array,array_size,delim);

And here is a code example:

#include


void main()
{
//if we have "Hello World" in test_file.txt
ifstream File("test_file.txt");
static char arr[10];
/*read, until one of these happens:
1) You have read 10
2) You met the letter “o”
3) There is new line
*/
File.getline(arr,10,’o');
cout << arr << endl; //it should display "Hell"
File.close();
}

peek() - This function will return the next character from an input file stream, but it won’t move the inside-pointer. I hope you remember, that get() for example, returns the next character in the stream, and after that, it moves the inside-pointer, so that the next time you call the get() function, it will return the next character, but not the same one. Well, using peek() will return a character, but it won’t move the cursor. So, if you call the peek() function, two times in succession, it will return a same character. Consider the following code example:

#include


void main()
{
//if we have "Hello World" in test_file.txt
ifstream File("test_file.txt");
char ch;
File.get(ch);
cout << ch << endl; //should display "H"
cout << char(File.peek()) << endl; //should display "e"
cout << char(File.peek()) << endl; //should display "e" again
File.get(ch);
cout << ch << endl; //should display "e" again
File.close();
}

And by the way, I forgot to mention- the peek() function actually returns the ASCII code of the char, but not the char itself. So, if you want to see the character itself, you have to call it the way I did, in the example.

_unlink() - Deletes a file. Include io.h in your program, if you are going to use this function. Here is a code example:

#include
#include


void main()
{
ofstream File;
File.open("delete_test.txt"); //creates the file
File.close();
_unlink("delete_test.txt"); //deletes the file
//tries to open the file, but if it does not exists
//the function will rreturn error ios::failbit
File.open("delete_test.txt",ios::nocreate);
//see if it returned it
if(File.rdstate() == ios::failbit)
cout << "Error...!\n"; //yup,it did
File.close();
}

putback() - This function will return the last read character, and will move the inside-pointer, one with -1 char. In other words, if you use get() to read a char, then use putback(), it will show you the same character, but it will set the inside-pointer with -1 char, so the next time you call get() again, it will again show you the same character. Here is a code example:

#include


void main()
{
//test_file.txt should have this text- "Hello World"
ifstream File("test_file.txt");
char ch;
File.get(ch);
cout << ch << endl; //it will display "H"
File.putback(ch);
cout << ch << endl; //it will again display "H"
File.get(ch);
cout << ch << endl; //it will display "H" again
File.close();
}

flush() - When dealing with the output file stream, the date you save in the file, is not actually immediately saved in it. There is a buffer, where it is kept, and when the buffer gets filled, then the data is put in the real file (on your disk). Then the buffer is emptied, and so on.
But if you want to save the data from the buffer, even if the buffer is still not full, use the flush() function. Just call it this way- FileHandle.flush(). And the data from the buffer will be put in the physical file, and the buffer will be emptied.
And something in addition (advanced)- The flush() function calls the sync() function of the associated streambuf. (The last sentence is from MSDN).

Conslusion

Well, I hope you can now do your File I/O programs! I covered everything I remembered of! I think it is more than enough for most of you! Even so, there are things I didn’t cover… but things I think you will never need. So, if you need even more advanced information on specific topic, search the web. Try google.com for example! But don’t ask me! I won’t answer any e-mails, asking me how to do certain program or else.

If you liked this tutorial, or not, I would be very happy to see your comments.
For more C++ tutorials, visit CPP Home

File I/O in C++ : part 1 of 2

Introduction

This tutorial will start with the very basis of File I/O (Input/Output) in C++. After that, I will look into aspects that are more advanced, showing you some tricks, and describing useful functions.
You need to have good understanding of C++, otherwise this tutorial will be unfamiliar and not useful to you!

Your Very First Program

I will first write the code, and after that, I will explain it line by line.
The first program, will create a file, and put some text into it.

#include
using namespace std;


int main()
{
ofstream SaveFile("cpp-home.txt");
SaveFile << "Hello World, from www.cpp-home.com!";
SaveFile.close();
return 0;
}

Only that? Yes! This program will create the file cpp-home.txt in the directory from where you are executing it, and will put “Hello World, from www.cpp-home.com!” into it.
Here is what every line means:

#include - You need to include this file in order to use C++’s functions for File I/O.
In this file, are declared several classes, including ifstream, ofstream and fstream, which are all derived from istream and ostream.

ofstream SaveFile("cpp-home.txt");
1) ofstream means “output file stream”. It creates a handle for a stream to write in a file.
2) SaveFile – that’s the name of the handle. You can pick whatever you want!
3) (”cpp-home.txt”); - opens the file cpp-home.txt, which should be placed in the directory from where you execute the program. If such a file does not exists, it will be created for you, so you don’t need to worry about that!
Now, let’s look a bit deeper. First, I’d like to mention that ofstream is a class. So, ofstream SaveFile(”cpp-home.txt”); creates an object from this class. What we pass in the brackets, as parameter, is actually what we pass to the constructor. It is the name of the file. So, to summarize: we create an object from class ofstream, and we pass the name of the file we want to create, as an argument to the class’ constructor. There are other things, too, that we can pass, but I will look into that, later.

SaveFile << "Hello World, from www.cpp-home.com"; - “<<" looks familiar? Yes, you’ve seen it in cout <<. This ("<<") is a predefined operator. Anyway, what this line makes, is to put the text above in the file. As mentioned before, SaveFile is a handle to the opened file stream. So, we write the handle name, << and after it we write the text in inverted commas. If we want to pass variables instead of text in inverted commas, just pass it as a regular use of the cout <<. This way:
SaveFile <<>
That’s it!

SaveFile.close(); - As we have opened the stream, when we finish using it, we have to close it. SaveFile is an object from class ofstream, and this class (ofstream) has a function that closes the stream. That is the close() function. So, we just write the name of the handle, dot and close(), in order to close the file stream!
Notice: Once you have closed the file, you can’t access it anymore, until you open it again.

That’s the simplest program, to write in a file. It’s really easy! But as you will see later in this tutorial, there are more things to learn!

Reading A File

You saw how to write into a file. Now, when we have cpp-home.txt, we will read it, and display it on the screen.
First, I’d like to mention, that there are several ways to read a file. I will tell you about all of them (all I know) later. For now, I will show you the best way (in my mind).
As you are used already - I will first write the code, and after that, I will comment it in details.

#include

void main() //the program starts here
{
ifstream OpenFile("cpp-home.txt");
char ch;
while(!OpenFile.eof())
{
OpenFile.get(ch);
cout << ch;
}
OpenFile.close();
}

You should already know what the first line is. So, let me explain you the rest.

ifstream OpenFile("cpp-home.txt") – I suppose this seems a bit more familiar to you, already! ifstream means “input file stream”. In the previous program, it was ofstream, which means “output file stream”. The previous program is to write a file, that’s why it was “output”. But this program is to read from a file, that’s why it is “input”. The rest of the code on this line, should be familiar to you. OpenFile is the object from class ifstream, which will handle the input file stream. And in the inverted commas, is the name of the file to open.
Notice that that there is no check whether the file exists! I will show you how to check that, later!

char ch; - Declares an array of type char. Just to remind you- such arrays can hold just one sign from the ASCII table.

while(!OpenFile.eof()) – The function eof() returns a nonzero value if the end of the file has been reached. So, we make a while loop, that will loop until we reach the end of the file. So, we will get through the whole file, so that we can read it!

OpenFile.get(ch); - OpenFile is the object from class ifstream. This class declares a function called get(). So, we can use this function, as long as we have an object. The get() function extracts a single character from the stream and returns it. In this example, the get() function takes just one parameter- the variable name, where to put the read character. So, after calling OpenFile.get(ch) it will read one character from the stream OpenFile, and will put this character into the variable ch.
Notice: If you call this function for a second time, it will read the next character, but not the same one! You will learn why this happens, later.
That’s why, we loop until we reach the end of the file! And every time we loop, we read one character and put it into ch.

cout <<> - Display ch, which has the read character.

File.close(); - As we have opened the file stream, we need to close it. Use the close() function, to close it! Just as in the previous program!
Notice: Once you have closed the file, you can’t access it anymore, until you open it again.

That’s all! I hope you understood my comments! When you compile and run this program, it should output:
“Hello World, from www.cpp-home.com!”

Managing I/O streams

In this chapter, I will mention about some useful functions. I will also show you how to open file to read and write in the same time. I will show you, also, other ways to open a file; how to check if opening was successful or not. So- read on!

So far, I have showed to you, just one way to open a file, either for reading, either for writing. But it can be opened another way, too! So far, you should be aware of this method:

ifstream OpenFile("cpp-home.txt");

Well, this is not the only way! As mentioned before, the above code creates an object from class ifstream, and passes the name of the file to be opened to its constructor. But in fact, there are several overloaded constructors, which can take more than one parameter. Also, there is function open() that can do the same job. Here is an example of the above code, but using the open() function:

ifstream OpenFile;
OpenFile.open("cpp-home.txt");

What is the difference you ask? Well, I made several tests, and found no difference! Just if you want to create a file handle, but don’t want to specify the file name immediately, you can specify it later with the function open(). And by the way, other use of open() is for example if you open a file, then close it, and using the same file handle open another file. This way, you will need the open() function.
Consider the following code example:

#include

void read (ifstream &T) //pass the file stream to the function
{
//the method to read a file, that I showed you before
char ch;
while(!T.eof())
{
T.get(ch);
cout << ch;
}
cout << endl << "--------" << endl;
}


void main()
{
ifstream T("file1.txt");
read(T);
T.close();
T.open("file2.txt");
read(T);
T.close();
}

So, as long as file1.txt and file2.txt exists and has some text into, you will see it!

Now, it’s time to show you that the file name is not the only parameter that you can pass to the open() function or the constructor (it’s the same). Here is a prototype:

ifstream OpenFile(char *filename, int open_mode);

You should know that filename is the name of the file (a string). The new here is the open mode. The value of open_mode defines how to be opened the file. Here is a table of the open modes:

Name Description
ios::inOpen file to read
ios::outOpen file to write
ios::appAll the date you write, is put at the end of the file. It calls ios::out
ios::ateAll the date you write, is put at the end of the file. It does not call ios::out
ios::truncDeletes all previous content in the file. (empties the file)
ios::nocreateIf the file does not exists, opening it with the open() function gets impossible.
ios::noreplaceIf the file exists, trying to open it with the open() function, returns an error.
ios::binaryOpens the file in binary mode.

In fact, all these values are int constants from an enumerated type. But for making your life easier, you can use them as you see them in the table.
Here is an example on how to use the open modes:

#include

void main()
{
ofstream SaveFile("file1.txt", ios::ate);
SaveFile << "That's new!\n";
SaveFile.close();
}

As you see in the table, using ios::ate will write at the end of the file. If I didn’t use it, the file will be overwritten, but as I use it, I just add text to it. So, if file1.txt has this text:

Hi! This is test from www.cpp-home.com!

Running the above code, will add “That’s new!” to it, so it will look this way:

Hi! This is test from www.cpp-home.com!That’s new!

If you want to set more than one open mode, just use the OR operator- |. This way:

ios::ate | ios::binary

I hope you now understand what open modes are!

Now, it’s time to show you something really useful! I bet you didn’t know that you could create a file stream handle, which you can use to read/write file, in the same time! Here is how it works:

fstream File("cpp-home.txt",ios::in | ios::out);

In fact, that is only the declaration. I will show you a code example, just several lines bellow. But I first want to mention some things you should know.
The code line above, creates a file stream handle, named “File”. As you know, this is an object from class fstream. When using fstream, you should specify ios::in and ios::out as open modes. This way, you can read from the file, and write in it, in the same time, without creating new file handles. Well, of course, you can only read or write. Then you should use either ios::in either ios::out, but if you are going to do it this way, why don’t you do it either with ifstream, either with ofstream?
Here is the code example:

#include

void main()
{
fstream File("test.txt",ios::in | ios::out);
File << "Hi!"; //put "Hi!" in the file
static char str[10]; //when using static, the array is automatically
//initialized, and very cell NULLed
File.seekg(ios::beg); //get back to the beginning of the file
//this function is explained a bit later
File >> str;
cout << str << endl;
File.close();
}

Okay, there are some new things here, so I will explain line by line:

fstream File("test.txt", ios::in | ios::out); - This line, creates an object from class fstream. At the time of execution, the program opens the file test.txt in read/write mode. This means, that you can read from the file, and put data into it, at the same time.

File << "Hi!"; - I beg you know what this is!

static char str[10]; - This makes a char array with 10 cells. I suppose static may be unfamiliar to you. If so- ignore it. It just initializes the array when at the time of creation.

File.seekg(ios::beg); - Okay, I want you to understand what this really do, so I will start with something a bit off-topic, but important.
Remember that? :
while(!OpenFile.eof())
{
OpenFile.get(ch);
cout << ch;
}

Did you ever wonder what really happens there? Yes or no, I will explain you. This is a while loop, that will loop until you reach the end of the file. But how do the loop know if the end of the file is reached? Well, when you read the file, there is something like an inside-pointer, that shows where you are up to, with the reading (and writing, too). It is like the cursor in Notepad. And every time you call OpenFile.get(ch) it returns the current character to the ch variable, and moves the inside-pointer one character after that, so that the next time this function is called, it will return the next character. And this repeats, until you reach the end of the file.
So, let’s get back to the code line. The function seekg() will put the inside-pointer to a specific place (specified by you). You can use:
ios::beg - to put it in the beginning of the file
ios::end - to put it at the end of the file
Or you can also set the number of characters to go back or after. For example, if you want to go 5 characters back, you should write:

File.seekg(-5);

If you want to go 40 character after, just write:

File.seekg(40);

I also have to mention, that the seekg() function is overloaded, and it can take two parameters, too. The other version is this one:

File.seekg(-5,ios::end);

In this example, you will be able to read the last 4 characters of the text, because:
1) You go to the end (ios::end)
2) You go 5 characters before the end (-5)
Why you will read 4 but not 5 characters? Well, just assume that one is lost, because the last thing in the file is not a character nor white space. It is just position.

You now may be wondering why did I use this function? Well, after I put “Hi!” in the file, the inside-pointer was set after it… at the end of the file. And as I want to read the file, I have nothing to read after the end, so I have to put the inside-pointer at the beginning. And that is exactly what this function does.

File >> str; - That’s new, too! Well, I believe this line reminds you of cin >> . I fact, it has much to do with it. This line reads one word from the file, and puts it into the specified array.
For example, if the file has this text:

Hi! Do you know me?

Using File >> str, will put just “Hi!” to the str array. You should have noticed, that it actually reads until it meets a white space.
And as what I put in the file was “Hi!” I don’t need to do a while loop, that takes more time to code. That’s why I used this way. By the way, in the while loop for reading, that I used so far, the program reads the file, char by char. But you can read it word by word, this way:

char str[30]; //the word can’t be more than 30 characters long
while(!OpenFile.eof())
{
OpenFile >> str;
cout << str;
}

You can also read it line by line, this way:

char line[100]; //a whole line will be stored here
while(!OpenFile.eof())
{
OpenFile.getline(line,100); //where 100 is the size of the array
cout << line << endl;
}

You now might be wondering which way to use? Well, I’d recommend you to use the line-by-line one, or the first that I mentioned- the one which reads char-by-char. The one that reads word-by-word is not good idea, because it won’t read the new line. So if you have new line in the file, it will not display it as a new line, but will append the text to the existing one. But using getline() or get() will show you the file, just as it is!

Now, I will show you how to check if the file opening was successful or not. In fact, there are few good ways to check for that, and I will mention them. Notice that where there is X, it can be either “o”, either “i” either nothing (it will then be fstream object).

Example 1: The most usual way

Xfstream File("cpp-home.txt");
if (!File)
{
cout << "Error opening the file! Aborting…\n";
exit(1);
}

Example 2: If the file is created, return an error

ofstream File("unexisting.txt", ios::nocreate);

if(!File)
{
cout << "Error opening the file! Aborting…\n";
exit(1);
}

Example 3: Using the fail() function

ofstream File("filer.txt", ios::nocreate);

if(File.fail())
{
cout << "Error opening the file! Aborting…\n";
exit(1);
}

The new in Example 3, is the fail() function. It returns a nonzero value if any I/O error (not end of file) has occurred.

I would also like to mention about something , that I find to be very useful! For example, if you have created a file stream, but you haven’t opened a file. This way:

ifstream File; //it could also be ofstream

This way, we have a handle, but we still have not opened the file. If you want to open it later, it can be done with the open() function, which I already covered in this tutorial. But if anywhere in your program, you need to know if currently there is an opened file, you can check it with the function is_open(). It retunrs 0 (false) if a file is not opened, and 1 (true) if there is an opened file. For example:

ofstream File1;
File1.open("file1.txt");
cout <<>

The code above, will return 1, as we open a file (on line 2). But the code bellow will return 0, because we don’t open a file, but just create a file stream handle:

ofstream File1;
cout <<>

Okay, enough on this topic.

Merry Chrismas

:D Hôm nay là giáng sinh rồi! Trong lịch của mình lại ko có ngày đó nhưng dù sao cũng chúc mọi người giáng sinh vui vẻ :D! Lang thang trên mạng 1 hồi kiếm được cái flash bài hát về giáng sinh rất hay :D

:D cái flash này có nhiều kiểu hát khác nhau đó

Xem riêng cái này


Lang thang 1 hồi nữa lại kiếm được 1 cái nữa :d
Tiếp này :D

Xem riêng cái này



;)) Lại kiếm thêm được cái nữa này
:D đi dọc lịch sử cùng ông già noel nào :d
Xem riêng cái này

Chủ Nhật, 20 tháng 12, 2009

Tất cả đã xong xuôi



:D Cuối cùng cũng làm xong bản mod tổng hợp cho lớp chỉ còn copy cho chúng nó cài nữa là xong. Vào bắn thử không ngờ mình lại lên tay đến thế =)). Bắn với 9 bot thì 8 headshot =)). Vui quá! (bắn bằng USP mới khủng)

Nhưng xem clip của các pro bắn pistol mà nể thật :D

Thứ Bảy, 19 tháng 12, 2009

Counter-Strike 1.6 Weapon Damage

5 vũ khí cơ bản nhất

Counter-Strike 1.6 Weapon Damage





USP


Giá tiền: $500
Số viên đạn/1 băng : 12
Tốc độ bắn: 7 viên /giây
Thời gian thay đạn: 2.7 giây
Dành cho cả Ts và CTs
Sức sát thương trung bình vào phần ngực không có giáp: 31hp
Sức sát thương trung bình vào phần ngực không có giáp (lắp giảm thanh): 26hp
Sức sát thương trung bình vào đầu không có giáp: 100 hp
Sức sát thương trung bình vào đầu không có giáp ( giảm thanh ): 100 hp
Sức sát thương trung bình vào phần ngực có giáp: 15 hp, 8 giáp
Sức sát thương trung bình vào phần ngực có giáp (lắp giảm thanh): 13 hp, 7 giáp
Sức sát thương trung bình vào phần đầu có giáp: 65 hp, 33 giáp
Sức sát thương trung bình vào đầu có giáp (lắp giảm thanh): 50 hp, 25 giáp

Glock18



Giá tiền: $400
Số viên đạn/1 băng: 20
Tốc độ bắn: 7 viên / giây
Thời gian thay đạn: 2.3 giây
Dành cho cả Ts và CTs
Sức sát thương trung bình vào phần ngực không có giáp: 18 hp
Sức sát thương trung bình vào phần đầu không có giáp: 82 hp
Sức sát thương trung bình vào phần ngực có giáp : 9 hp, 4 giáp
Sức sát thương trung bình vào phần đầu có giáp: 42 hp, 21 giáp


Deagle


Giá tiền: $650
Số viên đạn/1 băng: 7
Tốc độ bắn: 5 viên / giây
Thời gian thay đạn: 2.3 giây
Dành cho cả Ts và CTs
Sức sát thương trung bình vào phần ngực không có giáp: 58 hp
Sức sát thương trung bình vào phần đầu không có giáp: 100 hp
Sức sát thương trung bình vào phần ngực có giáp : 42 hp, 8 giáp
Sức sát thương trung bình vào phần đầu có giáp: 100 hp


m4a1


Giá tiền: $3100
Số viên đạn/băng: 30
Tốc độ bắn: 12 viên / giây
Thời gian thay đạn: 3 giây
Chỉ CTs mới có thể mua
Sức sát thương trung bình vào phần ngực không có giáp: 33 hp
Sức sát thương trung bình vào phần ngực không có giáp (Lắp giảm thanh): 29hp
Sức sát thương trung bình vào đầu không có giáp: 100 hp
Sức sát thương trung bình vào đầu không có giáp ( Lắp giảm thanh): 100hp
Sức sát thương trung bình vào phần ngực có giáp: 21 hp, 5 giáp
Sức sát thương trung bình vào phần ngực có giáp ( Lắp giảm thanh): 23hp, 5 giáp
Sức sát thương trung bình vào đầu có giáp : 89hp , 20 giáp
Sức sát thương trung bình vào đầu có giáp ( Lắp giảm thanh) : 85hp , 15 giáp


AK47




Giá tiền: $2500
Số viên đạn/ 1 băng : 30
Tốc độ bắn: 11 viên/giây
Thời gian thay đạn: 2.5 giây
Chỉ Ts mới có thể mua
Sức sát thương trung bình vào phần ngực không giáp: 38 hp
Sức sát thương trung bình vào phần đầu không giáp: 100 hp
Sức sát thương trung bình vào phần ngực có giáp: 27 hp, 4 giáp
Sức sát thương trung bình vào phần đấu có giáp : 100hp , 15 giáp


AWP



Giá tiền: $4750
Số viên đạn / 1 băng: 10 viên
Tốc độ bắn: 0.75 viên/giây
Thời gian thay đạn: 2.6 giây
Cả Ts và CTs đều có thể mua
Sức sát thương trung bình vào phần ngực không giáp: 100 hp
Sức sát thương trung bình vào phần đầu không giáp: 100 hp
Sức sát thương trung bình vào phần ngực có giáp: 100 hp
Sức sát thương trung bình vào phần đầu có giáp: 100 hp

Các loại vũ khí trong Counter-Strike

Giới thiệu sơ lượt về các loại vũ khí trong Counter-Strike , và đặc tính của từng loại vũ khí đó

1/Dao


Sản xuất : Strider Knives
+ Mức độ nguy hiểm : Low
+ Kô tốn tiền

Dùng dao thì tốt nhất là đâm bằng Mouse2 (phím phải chuột) . Khi áp sát đối phương hãy đâm . Khi đâm giữ nguyên nút Mouse2 . Khi đâm đối diện có thể dùng phương pháp lạng qua một bên rồi lia chuột về hướng đối phương trong khi vẫn giữ nguyên nút đâm . Cố gắng đâm vào đầu nếu kô phải 2 phát mới chết

2/Súng lục:
USP (Universal Self-Loading Pistol)



+ Sản xuất : Heckler & Koch
+ $500
+ Băng đạn 12 viên
+ Có ống giảm thanh (tháo lắp)
+ Kiểu đạn : .45 ACP
+ Sát thương : Trung bình khá
+ Tốc độ : Trung bình
+ Lên đạn : Nhanh

Khẩu này bắn khá chính xác . Bắn bằng cách nhắp liên tục nút bắn . Vùng nhắm : Ngực và đầu

Glock 18C Select Fire




+ Sản xuất : Glock
+ $400
+ Đặc điểm : có thể chuyển qua lại giưã hai kiểu bắn . Bắn từng viên và bắn nhiều viên 1 lúc
+ Độ sát thương : normal với 1 viên và high với 3 viên
+ Tốc độ bắn : Bình thường với 1 viên và chậm với 3 viên
+ Kiểu đạn : 9mm
+ 20 viên trong một băng đạn
+ Tốc độ lên đạn (Reload) : nhanh

Đây là khẩu default của Cướp . Rất chính xác tuy hơi yếu khi bắn từng viên nhưng khi chuyển sang 3 viên một lần thì mạnh . Khi bắn thì nhắm vào đầu .

Desert Eagle



+ Sản xuất : Magnum Research/Israeli Military Industries
+ $650
+ 7 viên trong một băng đạn và mang nhiều nhất là 35 viên
+ Đặc điểm riêng : kô có
+ Độ sát thương : High
+ Tốc độ và độ chính xác : bình thường
+ Kiểu đạn : .50AE slugs
+ Reload : Bình thường

Đạn mạnh là ưu điểm để chọn DG đi cùng súng ngắm . Nó chính xác nhất trong 1,2,3 viên đầu . Mau hết đạn là yếu điểm duy nhất của nó . Chỉ cần trúng 2-3 viên là chết . 2 viên đầu nên nhắm vào đầu . Từ viên thứ 3 trở đi thì nhắm vào ngực .

P228



Sản xuất : SIG Sauer
+ $600
+ Băng đạn 13 viên 357SIG . Maximum 53 viên mang theo
+ Độ sát thương cao
+ Độ chính xác :bình thường
+ Reload : Hơi chậm

Dùng để bắn kẻ địch mặc giáp rất tốt . Khi bắn thì ngắm vào đầu và phần trên ngực một tí.

Dual 96G Elite Berettas (Chỉ dành cho Terrorist)



+ Sản xuất : Beretta
+ $1000
+ 30 viên đạn cho cả hai súng với kiểu đạn 9mm . Có thể mang tối đa 120 viên
+ Độ sát thương và độ chính xác bình thường
+ Reload : Hơi chậm

Cặp súng này nhìn thì đẹp nhưng it được sử dụng vì yếu và kô chính xác , giá tiền thì đắt và chỉ được cái bắn lâu vì có những 30 viên đạn.

FiveseveN (Chỉ dùng cho CT)

.

+ Sản xuất : Fabrique Nationale
+ $750
+ Băng đạn 20 viên với kiểu đạn 5.7mm . Mang tối đa là 100 viên
+ Độ sát thương tuy hơi yếu nhưng rất chính xác
+ Reload : Hơi chậm

Tuy cực kì chính xác nhưng yếu nên phải có đến 20 viên đạn . Bắn vào sọ cũng phải 2-3 phát nên ít dùng

3/Vũ khí chính:

Shotgun

M3 Super 90 Entry



+ Sản xuất : Benelli
+ $1700
+ 8 viên đạn mỗi băng với kiểu đạn 12-Gauge shells . Mang tối đa là 32 viên
+ Độ sát thương rất cao khi ở gần và yếu khi ở xa
+ Càng xa độ chính xác càng giảm
+ Tốc độ bắn : chậm
+ Reload : bình thường

Đặc điểm duy nhất của khẩu này là sức mạnh khủng khiếp khi ở gần còn nữa là như sh1t . Lưu ý là khẩu này kô dùng được khi ở dưới nước . Vùng nhắm khi ở gần : cổ

XM1014 (M4 Super 90)



+ Sản xuất : Benelli/Heckler & Koch
+ Băng đạn 7 viên với kiểu đạn 12-Gauge shells . Mang tối đa 32 viên .
+ Chính xác khi ở gần và càng xa thì độ chính xác càng giảm . Độ sát thương cũng thế .
+ Tốc độ bắn của khẩu này khá nhanh
+ Reload : bình thường

Cũng giống như khẩu SG trên nhưng khẩu này bắn nhanh hơn . Ở dưới nước cũng kô dùng được

Nói chung là SG chỉ thích hợp với map nhỏ cận chiến như Ice còn dùng ở trong thi đấu thì hầu như là kô.

Sub-Machine

MP5-Navy



+ Sản xuất : Heckler & Koch
+ Băng đạn 30 viên với kiểu đạn 9mm slugs . Mang tối đa là 120 viên
+ Độ chính xác cao nhưng độ sát thương thì bình thường
+ Tốc độ của đạn cao
+ Reload : Cực kì nhanh

Trước đây đây là khẩu súng được ưa chuộng nhất bởi nhiều ưu điểm của nó : bắn nhanh , chính xác , tốc độ lên đạn cao . Nó là sự khó chịu với bất kì địch thù nào . Nhưng hiện nay đạn yếu là nhược điểm chết người của nó khi mà trình độ sử dụng súng đã được nâng cao lên . Vì thế khẩu này bây giờ chỉ còn hữu dụng khi tiền ít . Khi bắn nhắm vào : Đầu và cổ.

teyr Tactical Machine Pistol (TMP) (Counter-Terrorists)



+ Sản xuất : Steyr
+ $1250
+ Băng đạn 30 viên với kiểu đạn 9mm slugs . Mang tối đa là 120 viên
+ Độ sát thương yếu và độ chính xác trung bình
+ Tốc độ bắn cũng như lên đạn rất nhanh

Một khẩu súng rất hay bởi tốc độ bắn và độ yên lặng khi giết kẻ thù nhưng hãy nhớ một điều đây là một khẩu súng rất yếu vì thế nó kô nên dùng . Khi bắn thì nữa băng đầu nhắm vào đầu còn nữa băng sau thì nhắm vào ngực.

P90 Personal Defense



Sản xuất : Fabrique Nationale
+ $2350
+ Băng đạn 50 viên với kiểu đạn 5.7mm slugs . Mang tối đa là 100 viên
+ Độ sát thương cao , tốc độ bắn cực nhanh nhưng độ chính xác thì trung bình
+ Lên đạn chậm

Đây là khẩu súng bắn nhanh nhất trong CS nhưng ít được dùng . Khi bắn chú ý độ giật khá cao.

MAC-10 (Terrorists only)



+ Sản xuất : Ingram
+ $1400
+ Băng đạn 30 viên với kiểu đạn .45ACP slugs . Mang tối đa là 90 viên
+ Độ sát thương cao , tốc độ bắn cực nhanh nhưng độ chính xác thì quá kém và phạm vi sử dụng ngắn
+ Lên đạn nhanh

Nói chung đây là một khẩu sh!t gun.

Universal Machinenpistole



+ Sản xuất : Heckler & Koch
+ $1700
+ Băng đạn 25 viên với kiểu đạn 45ACP slugs . Mang tối đa là 90 viên
+ Độ sát thương cao nhưng tốc độ bắn chậm , độ chính xác thì trung bình khá
+ Lên đạn chậm

Đây xứng đáng là ông anh của MP5 về sức mạnh nhưng bắn chậm và lên đạn chậm làm giảm ưu điểm của nó . Tốt nhất là đưng dùng nó.

Rifles

IMI Galil (Terrorist Only)



+ Sản xuất : Israeli Military Industries
+ $2000
+ Băng đạn 35 viên với kiểu đạn .308 Caliber . Mang tối đa là 90 viên
+ Tốc độ bắn nhanh nhưng độ chính xác và sức mạnh trung bình
+ Lên đạn trung bình khá

Sự lựa chọn số 1 cho T khi ít tiền . Nhiều người coi nó là sư phụ của MP5 he he . Giật yếu hơn AK nhưng độ sát thương thì kô kém . Bắn nên chọn vùng ngực và kìm chuột

FAMAS (Counter-Terrorist Only)



+Sản xuất : Groupement Industriel des Armements Terrestres
+ $2250
+ Băng đạn 25 viên với kiểu đạn 5.56mm NATO . Mang tối đa là 90 viên
+ Đặc điểm riêng : Three-Round Burst
+ Độ sát thương trung bình . Khi bắn 3 viên một lần thì độ chính xác trung bình khá còn nếu bắn Full Auto thì độ chính xác kém. Tốc độ bắn khá cao
+ Reload : Hơi chậm

Khẩu này khá rẻ tuy nhiên lại yếu . Mặc dù vậy nó vẫn hơn xa MP5 về độ sát thương . Khi bắn xa nên chọn chế độ bắn 3 viên một lần để tăng độ chính xác lên .

Avtomat Kalashnikov Model 47 (AK-47)



+ Sản xuất: Kalashnikov
+ $2500
+ Băng đạn 30 viên với kiểu đạn 7.62mm slugs . Mang tối đa là 90 viên
+ Độ sát thương cao , tốc độ bắn nhanh . Với từng tràng nhỏ thì vô cùng chính xác nhưng nếu bắn nguyên băng thì lại rất giật
+ Reload : Hơi chậm

Đây là sự lựa chọn số 1 dành cho cướp và là 1 trong 3 khâủ súng cần sử dụng thành thạo khi chơi CS . Kiểu bắn thì đọc trong topic về AK . Tốt nhất là kết hợp bắn một tràng nhỏ vào đầu kéo dần xuống ngực , nếu đủ gần thì tiếp theo ngồi xuống và xả đạn theo phương pháp tâm ngắm phía trên của Crosshair nằm ở ngực và kéo xuống chân theo thời gian bắn.

SG-552 Commando (Terrorists Only)



+ Sản xuất: SIG
+ $3500
+ Băng đạn 30 viên với kiểu đạn 5.56mm slugs . Mang tối đa là 90 viên
+ Đặc điểm riêng : 2x zoom
+ Độ sát thương và tốc độ bắn cao , khoảng cách bắn xa nhưng độc chính xác thì trung bình nếu bắn từng loạt và giật nếu bắn nguyên băng
+ Lên đạn : chậm

Đây là khẩu súng khá mạnh tuy nhiên giật vô cùng . Khi bắn thì kô nên bắn nguyên băng mà nên giữa chừng chuyển sang chế độ ngắm . Chú ý là khi ngắm thì tốc độ bắn sẽ giảm.

M4A1 Carbine with Silencer (Counter-Terrorists Only)



+ Sản xuất : Colt
+ $3100
+ Băng đạn 30 viên với kiểu đạn 5.56mm slugs . Mang tối đa là 90 viên
+ Đặc điểm riêng : có ống giảm thanh
+ Độ sát thương và tốc độ bắn cao . Độ chính xác cũng rất tốt
+ Reload : bình thường

Đây là khẩu súng hay nhất của CT . Nó rất linh hoạt trong sử dụng có thể bắn từng tràng (khi bắn ngắm vào đầu và ngực ) hay có thể kéo nguyen băng (khi bắn tâm trên của Crosshair nằm ở ngực đối phương) . Nó có thể âm thầm giết người với ống giảm thanh tuy nhiên khi lắp vào thì độ sát thương sẽ giảm đi . Đây là khẩu thứ 2 cần phải thành thạo trong 3 khẩu cần biết khi chơi CS


Steyr AUG A1 (Counter-Terrorists Only)



+ Sản xuất : Steyr
+ $3500
+ Băng đạn 30 viên với kiểu đạn 5.56mm slugs . Mang tối đa là 90 viên
+ Đặc điểm riêng : 1.4x zoom
+ Độ sát thương và khoảng cách bắn xa . Rất chính xác khi bắn từng tràng và giảm dần đi khi bắn nguyên băng . Tốc độ bắn cao
+ Reload : trung bình

Đây là một trong những khẩu mạnh nhất trong CS với tâm ngắm nhỏ nên những viên đầu tiên rất dễ vào đầu . Nó thích hợp với cự ly xa tuy nhiên lại kô chính xác ở những phát sau .Khi bắn chú ý chuyển qua ngắm khi bắn nửa chừng nhưng cũng đừng quên ngắm thì tốc độ bắn sẽ giảm đi


Scout



+ Sản xuất : Steyr
+ $2750
+ Băng đạn 10 viên với kiểu đạn 7.62mm slugs . Mang tối đa là 60 viên
+ Đặc điểm riêng : 2.25x zoom/6x zoom
+ Độ sát thương cũng như tốc độ bắn và tốc độ lên đạn trung bình nhưng lại nhẹ nên di chuyển linh hoạt và lại rất chính xác

Nó rẻ nên đối với những player nghiện súng ngắm mà thiếu tiền thì xứng đáng là một toy kô thể bỏ qua . Đọc thêm về topic Scout trong box để biết thêm chi tiết


Arctic Warfare Magnum (AWP or AWM)



+ Sản xuất : Accuracy International
+ $4750
+ Băng đạn 10 viên với kiểu đạn 338 Lapua . Mang tối đa là 30 viên
+ Đặc điểm riêng :2.25x zoom/9x zoom
+ Độ sát thương và tầm bắn khủng khiếp tuy nhiên tốc độ bắn và lên đạn chậm

1 shot 1 kill !!! Khẩu thứ 3 cần thành thạo khi chơi CS . Đọc thêm topic súng AWP để biết thêm chi tiết


G3/SG-1 Precision Sniper Rifle (Terrorist Only



+ Sản xuất : Heckler & Koch
+ $5000
+ Băng đạn 20 viên với kiểu đạn 7.62mm slugs . Mang tối đa là 60 viên
+ Đặc điểm riêng :2.25x zoom/6x zoom
+ Độ sát thương khá và khoảng cách bắn xa , tốc độ bắn khá nhanh nhưng độ chính xác thì trung bình và tốc độ lên đạn chậm

Đây chính là đứa con lai của Súng ngắm và súng tự động tuy nhiên nó kô xứng đáng với số tiền bỏ ra . Độ sát thương kô mạnh và giật làm cho nó khó dùng . Khi bắn chỉ nên bắn 1 lầm 5 viên và ngồi bắn để tăng độ chính xác


SG-550 Sniper Rifle (Counter-Terrorist Only)



+ Sản xuất : SIG
+ $4200
+ Băng đạn 30 viên với kiểu đạn 5.56mm slugs . Mang tối đa là 90 viên
+ Đặc điểm riêng : 2.25x zoom/6x zoom
+ Khoảng cách bắn xa, tốc độ bắn khá nhưng độ sát thương thì trung bình và lên đạn chậm

Nó giống khẩu G3 tuy nhiên mang được nhiều đạn hơn nhưng đổi lại độ sát thương lại giảm đi.
Tham khảo gamethu.net

Chủ Nhật, 13 tháng 12, 2009

Tự dưng buồn!

Hôm nay ở nhà ôn thi! Mai báo cáo môn Mạng máy tính, thứ 4 thì thi môn Công nghệ phần mềm mà vẫn chưa học được cái gì cả! Nản quá! Nhìn cái ảnh kia rồi lại nhớ! Lang thang nghe nhạc tự dưng gặp lại 2 bài của nhóm N9 :D Tiện thế ghé qua cái blog post bài luôn :D





Mấy bài này tuy cũ rồi nhưng nghe vẫn hay ghê :D

Thứ Năm, 10 tháng 12, 2009

[FC]Goats

Cuối cùng đã xong project này :D! Khách hàng đã ok rồi! Dự án đầu tiên phân tích còn chưa kỹ và cơ sở dữ liệu còn lung tung nhưng chạy rất luột :D! Nhưng 2 tuần rồi chưa thấy khách hàng phản hồi ý kiến gì! Chứng tỏ soft chạy tốt chưa phát sinh lỗi nghiêm trọng! He he! Nghĩ lại công nhận mình và thằng kia liều thật! Lần nhận project hai đứa vẫn chưa có định hướng rõ ràng thế mà cũng xong :D

Thứ Ba, 1 tháng 12, 2009

Gió, Cây Và Lá

Gió, Cây Và Lá
Trình bày: Zinken - Feat: Rainie Thao Vy
Sáng tác: Zinken - Rainie Thao Vy




[Rainie:]
Oh………yeah. Wo………oh
Gió cùng mây đến phương nào
Và anh đã ra đi thật xa rồi
Dẫu cho người đã đi xa em ngồi nơi đây vẫn chờ nhớ anh mong người mãi quay về

> >

[Zinken:]
gió cây và lá chuyện tình yêu 3 người chúng ta
cây yêu lá gió muốn lá
nhưng vì sao lá lại yêu cây chọn cây ko chọn gió
vẫn ko chịu cùng gió bay đi đến một phương trời mới
Một mơ ước gió thổi lá cuốn trôi đi hiện lên trong đầu của gió
mình phải cuốn lá đi
mình phải mang lá đi theo mình ko thể để ở bên cây
và cơn bão đã đến cuốn đi những chiếc lá cuối cùng của cây đi
bay đi đâu thì ai ko biết bay về đâu thì ai biết đc? chỉ biết hỏi gió mà thôi
Những ngày sau gió ko quay lại...ko quay lại đc đến lần thứ 2
và gió đâu thể ngờ trên cây kia còn 1 chiếc lá
Một chiếc lá mong manh hiền lành như hạt sương tàn dễ vỡ
Sẽ có lúc lá lìa cành nhưng cây ko muốn đâu
cây vẫn muốn ôm lá bên mình nhưng rồi....
Nhưng rồi lá rơi xuống như giọt nước mắt của cây
nhưng ai đâu biết đâu chuyện tình yêu giữa cây và lá mới chỉ bắt đầu
lá xuống gốc để ôm trọn lấy cây như cây đã từng che chở cho lá qua cơn bão giống phải ko ?
Gió, Cây Và Lá lyrics on
http://music.yeucahat.com/song/Karaoke-room/25120-Gio-Cay-Va-La~Zinken-Feat-Rainie-Thao-Vy.html


> >

[Rainie:]
Dẫu ánh dương kia vội tan và mãi nhớ về một người đi xa
Dẫu tình ta đùa vui thế thôi người ơi vẫn mong khung trời ngày xưa
Ước mơ nay còn đâu người đã đi rồi để lòng đau đớn
Dẫu tình ta đùa vui thế thôi người ơi vẫn mong khung trời ngày xưa có anh

> >

Người yêu ơi mình chia ly vậy sao?
Giọt nước mắt em rơi như chiếc lá trên cành kia khô héo
Và người vẫn không trở về trong bao ư ớc m ơ
Em vẫn nhớ ngày xưa từng nụ hôn mình đã trao dưới mưa
Từng lời anh nói sẽ yêu em trọn đời

> >

Một tình yêu giờ đây chẳng còn chi vì người đã ra đi vì người đã quên đi ngày xưa
Bao nhiêu lời anh hứa đã vỡ tan thành mưa
Người con gái ngày xưa nay đã không còn nữa
Như lá rơi lá cuốn lá rơi xuống bỏ lại cây một mình nơi đây
Ôi vì sao vì sao cuộc tình là hư ảo là một giấc chiêm bao bay lên trời cao
Bay đến muôn vì sao cho bao giọt nước mắt hao gầy
Em vẫn ngồi nơi đây và nhớ nhớ
Nhớ bao nhiêu giấc mơ nhớ những ngày thơ

Để giờ đây mình em bơ vơ để mình em mong chờ
Dẫu biết rằng ở nơi xa người vẫn ơ thờ
Người vẫn không hề nhớ nhưng vẫn mong
Lá ấy trở về bên cây