ChinaUnix.net
相关文章推荐:

C string

[code]#include #include <string> using namespace std; int main() { string s; s[0] = 'a'; s[1] = 'b'; s[2] = 'c'; cout << s << endl; }[/code]为什输出为空白?但是输出s[0]~s[2]的时候却能输出单个字母。是和string类的定义有关吗

by lambert_fan - C/C++ - 2011-02-24 13:27:34 阅读(3047) 回复(12)

相关讨论

今日终于得闲,不用读fucking algorithm,study shit data structure!!!那就看看string吧,其实string以前写过,奈何这种东东基本上不用时隔多久就会忘掉忘掉的!!!注明下我这里这个string.c是lib/string.c下的, stupid library routines.. The optimized versions should generally be found as inline code in !!! 但是只有这个stupid library才是我所懂的,optimized versions全是汇编,想看自己去看了,在下是不会汇编的!!! ...

by ubuntuer - Linux文档专区 - 2009-09-29 16:40:40 阅读(584) 回复(0)

之所以抛弃char*的字符串而选用c++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够、字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是100%)的需要。我们可以用 = 进行赋值操作,== 进行比较,+ 做串联(是不是很简单?)。我们尽可以把它看成是c++的基本数据类型。 好了,进入正题……… 首先,为了在我们的程序中使用string类型,我们必须包含头文件 。如下: ...

by 第一支烟 - Linux文档专区 - 2007-08-10 09:26:40 阅读(938) 回复(0)

发现这样代码: test.h std::string test(std::string param); test.c string test(string param) { string ipaddr,port,option; string ret; if(param.find_first_not_of("1234567890")!=string::npos){ string errs = "数据类型错误"; ret = formaterrmsg(errs); return ret; } vector<string> cmd; return ret; }...

by peterdocter - C/C++ - 2007-07-20 17:20:54 阅读(2826) 回复(8)

张三,3456123, 湖南 | 李四,4564234, 湖北|王小二, 4433253, 北京| 。。。 请以 "|" ","为分隔符,同时又要过滤空格,把每行分成相应的字段 用string实现,help!谢谢各位

by dclmail - C/C++ - 2006-05-08 14:35:10 阅读(1092) 回复(5)

问题源自于c++primer中的一道习题 疑问1:p78 练习题3.9 和 书上关于string下标的说法貌似有矛盾? 书上:如果string 不为空的话, 那么s[0]就是其第一个字符,s[s.size() - 1] 就是其最后一个字符. 但是 练习题 中的string 为空,长度为0 , 然而 cout << s[0] 或是 cout << s[1] 竟然没有出错!编译通过且运行无错! 程序: #include <string> #include using namespace std; int main() { string s; ...

by chmj1222 - C/C++ - 2011-06-02 10:11:08 阅读(1804) 回复(3)

各位大侠,能不能帮忙看看我的这个程序哪里有问题。 运行没有错误,也可以连接到mysql,但就是不能把数据从mysql中调出。 我是新手,但是我的直觉告诉我,是在什么地方把命令的顺序搞错了。 还希望各位前辈多费心指点一下。 //---------------代码 sql::Driver *driver; sql::connection *con; sql::Statement *stmt; sql::ResultSet *res; /* create a connection */ driver = get_driver_instance(); con = driver->connect("lo...

by qk00001 - C/C++ - 2009-12-02 19:27:27 阅读(1569) 回复(3)

[quote] #include std::string string_1(void) { std::string s="str1\n"; return s; } std::string &string_2(void) { std::string s = "&str2\n"; return s; } char *string_3(void) { char *p; p="str3\n"; return p; } char *string_4(void) { char p[] = "[]str4\n"; return p; } int main(int argc,char **argv) { std::cout<<string_1(); std::cout<<string_2(); std::cout<<string_3(); std::...

by pcwkt - C/C++ - 2009-01-03 09:58:36 阅读(4141) 回复(16)

我用微软的Vc++6.0学习c++,请问怎么使用string型变量? 我写的一段代码: #include ; #include <string.h>; int main() { string ss; cin >;>; ss; cout<configuration: a - Win32 Debug-------------------- compiling... a.cpp F:\ch\a.cpp(5) : error c2065: 'string' : undeclared identifier F:\ch\a.cpp(5) : error c2146: syntax error : missing ...

by meixue - C/C++ - 2010-05-23 17:27:01 阅读(4591) 回复(14)

c++ string: How to convert between 'cstring' and 'std::string'? 'cstring' to 'std::string': std::string cannot always construct from a LPcTSTR i.e. the code will fail for UNIcODE builds. So the following conversion will lead to error: cstring cs("Hello"); std::string s((LPcTSTR)cs); As std::string can construct only from LPSTR / LPcSTR, a programmer who uses Vc++ 7.x or better can utilize conver...

by so_brave - C/C++ - 2011-06-07 17:04:18 阅读(2499) 回复(1)

代码1:[code]#include using namespace std; int main(int argc, char** argv) { string s("Hello World!"); cout << s << endl; return 0; } [/code]代码2:[code]#include int main(int argc, char** argv) { string s("Hello World!"); std::cout << s << std::endl; return 0; } [/code]代码1运行正常 代码2编译出错,提示string没有定义。 这...

by zjw0722 - C/C++ - 2014-07-19 20:15:54 阅读(2308) 回复(8)