
C++语言
u010969626
这个作者很懒,什么都没留下…
展开
-
the first day C++中结构体的使用
#include"stdafx.h"#include#includeusingnamespacestd;structStructure1{charc;inti=9;floatf;doubled;}; int_tmain(intargc,_TCHAR*原创 2015-09-02 10:54:35 · 245 阅读 · 0 评论 -
与旧代码的接口(C++中C_str()的用法)
#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ string s("hello world"); char *str = s; cout << *str; const char *str1= s.c_str(); cout << endl << *str1; return 0;}不能用st原创 2017-02-24 16:59:15 · 382 阅读 · 0 评论 -
字符串
#include#include#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ const char ca[] = { 'h', 'e', 'l', 'l', 'o' }; const char *cp = ca; while (*cp){ cout << *cp << endl; ++c原创 2017-02-24 14:58:09 · 183 阅读 · 0 评论 -
比较字符串
#include "stdafx.h"#include#include#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ string s1 = "A string example"; string s2 = "A different string"; cout << (s2 <s1) << end原创 2017-02-24 14:48:59 · 236 阅读 · 0 评论 -
string::size_type类型
#include "stdafx.h"#include#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ string line; string::size_type i=0; while (getline(cin, line)){ if (line.size() > 10){ cout原创 2017-02-18 18:55:02 · 400 阅读 · 0 评论 -
string的empty和size操作
#include "stdafx.h"#include#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ string line; while (getline(cin, line)){ if (!line.empty()) cout << line << endl; } return原创 2017-02-18 18:31:36 · 838 阅读 · 0 评论 -
使用getline读取一整行
#include "stdafx.h"#include#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ string line; while (getline(cin, line)) cout << line; return 0;}输出结果为:原创 2017-02-18 18:15:16 · 920 阅读 · 0 评论 -
C++(定义和初始化string对象)
#include "stdafx.h"#include#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ string s1; string s2; string s3 = "hiya"; string s4(10, 'c'); string s5(s3 + s4); cout << s1 <原创 2017-02-18 17:49:15 · 4845 阅读 · 0 评论 -
C++ vector 的简单用法
C++ vector 的简单用法include “stdafx.h”includeinclude include using namespace std;int _tmain(int argc, _TCHAR* argv[]) { vector SS;SS.push_back("The number is 10");SS.push_back("The number is 20");转载 2016-05-11 17:23:43 · 375 阅读 · 0 评论 -
含有无符号类型的表达式
#include "stdafx.h"#include#include#includeusing namespace std;int _tmain(int argc, _TCHAR* argv[]){ for (unsigned u = 10; u >= 0; --u){ cout << u << endl; } return 0;}上述代码有问题,变量u永远也不会小于0原创 2017-02-25 13:48:02 · 268 阅读 · 0 评论