ÓйØstring Óë namespace µÄÎÊÌâ¡£
#inclust <iostream>#inclust <string>
int main()
{
string str_1;
str_1 = "hello world ";
std::cout<<str_1<<std::endl;
return 0;
}
Ϊʲô²»ÐÐÄØ£¿
¶ø£º
#inclust <iostream>
#inclust <string>
using namespace std;
int main()
{
string str_1;
str_1 = "hello world ";
cout<<str_1<<endl;
return 0;
}
ÕâÑù¾Í¿ÉÒÔÁË£¿ÎªÊ²Ã´ ÄØ£¿ [code]
#include <iostream>
#include <string>
int main()
{
[color=red]std::[/color]string str_1;
str_1 = "hello world";
std::cout << str_1 << std::endl;
}
[/code] ºÃÏó×Ö·û´Ü²»ÄÜÖ±½Ó¸³Öµ°É!! Ϊʲô²»ÄÜ£¿ char *Ö±½Ó¸³Öµ»á²úÉú±ðÃûÎÊÌâ,string²»»á,ÔÒòÂï,¿ÉÒÔ¿´¿´operator =ÖØÔØ.ÖÁÓÚһ¥µÄÎÊÌâ,Ó¦¸ÃÕÒ±¾c++µÄÊé¿´¿´Ãû×Ö¿Õ¼äµÄ¸ÅÄî [QUOTE=zealotcat]char *Ö±½Ó¸³Öµ»á²úÉú±ðÃûÎÊÌâ,string²»»á,ÔÒòÂï,¿ÉÒÔ¿´¿´operator =ÖØÔØ.ÖÁÓÚһ¥µÄÎÊÌâ,Ó¦¸ÃÕÒ±¾c++µÄÊé¿´¿´Ãû×Ö¿Õ¼äµÄ¸ÅÄî[/QUOTE]
ʲôÊÇ¡°±ðÃû¡±ÎÊÌ⣿ [QUOTE]
#include<iostream>
#include<string>
int main()
{
string str_1;
str_1 = "hello world ";
std::cout<<str_1<<"\n";
return 0;
}[/quote]
¼õÉÙDZÔÚµÄÃû×Ö³åÍ» #inclust <iostream>
#inclust <string>
¾Í±ØÐëÒªÓÃÃû×Ö¿Õ¼äµÄ£¬ÕâÊÇc£«£«µÄ±ê×¼°¡
Èç¹ûÓþɵÄ
#include <iostream.h>¾Í²»ÓÃusing namespace std;
Ò³:
[1]