kiem tra code

3 views
Skip to first unread message

nguyễn phát tài - ITPRO

unread,
Aug 4, 2010, 1:41:05 PM8/4/10
to OOP-He2010
tại sao đoạn code này lại báo lỗi.thầy và các bạn hãy kiểm tra giúp
mình thanks!!!!!!!!!


#include "iostream.h"
#include "stdlib.h"
#include "string"

using namespace std;

void sort(int n,string str[]);

void main ()
{
string str1("1234");
string str2("56789");
string s = str1 + str2;
cout<<"Result : "<< s <<endl;
string country[]={"viet nam","lao","campuchia","thai lan","trung
quoc"};
int n=5;
sort(n,country);
cout<<"after sorting : "<<endl;
for (int i=0;i<n;i++)
cout <<"\t"<< country[i] <<endl;
system("PAUSE");

}
void sort (int n,string str[])
{
for (int i=0;i<n-1;i++)
for (int j=0;j<n;j++)
if (str[i] >str[j])
{
string s=str[i];
str[i]=str[j];
str[j]=s;
}
}

Toan Nguyen Van

unread,
Aug 4, 2010, 8:51:43 PM8/4/10
to oop-he2010, nguyenphattai01
Chào em!
Tôi thử chạy bằng DevC++ và thấy chương trình chạy được, chỉ cần bỏ đi void trước hàm main
Result :   123456789
after sorting :
        viet nam
        thai lan
        lao
        campuchia
        trungquoc
Press any key to continue . . .

--------------------------------------------
Nguyễn Văn Toàn
Trường Đại học Công nghệ thông tin - ĐHQG HCM
ĐT: 0903761559
Email: toa...@uit.edu.vn


2010/8/5 nguyễn phát tài - ITPRO <nguyenp...@yahoo.com.vn>

damchau_ Bio club

unread,
Aug 8, 2010, 8:52:54 PM8/8/10
to OOP-He2010
hình như so sánh 2 chuỗi phải dùng hàm strcmp phải ko thầy

nguyễn phát tài - ITPRO

unread,
Aug 9, 2010, 1:19:37 AM8/9/10
to OOP-He2010
mà có điều em không hiểu tại sao trên Dev C++ chương trình lại chạy
còn trên visual c++ 6.0 nó lại báo lỗi e thử chạy trên visual studio
2008 cũng không chạy vậy thầy.

Pro khanh

unread,
Aug 9, 2010, 4:10:45 AM8/9/10
to oop-h...@googlegroups.com
bạn kiểm tra đã thông báo thư viện chưa? Copy sẽ khó hiểu vấn đề lắm. Tốt nhất là write code lại. (^^).
Sorry if i wrong!!!

Reply all
Reply to author
Forward
0 new messages