tring_vector容器test

// string_vector_test.cpp : 定义控制台应用程序的入口点。
//


#include "stdafx.h"
#include<iostream> // cout , endl etc
#include<string>
#include<vector>


using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
cout << "Huoyanjun test!!!" << endl;
string str = "hello!!";
char tmp_c = '2';


cout << str <<endl;
str += "c";
cout << str << endl;
str += tmp_c;
cout << str << endl;
{
string shuzi_str_zheng = "123";
int tmp_int = atoi(shuzi_str_zheng.c_str());
printf("-->tmp_int:%d;-->shuzi_str_zheng.c_str():%s;\n", tmp_int, shuzi_str_zheng.c_str());
}


{
string shuzi_str_zheng = "-123";
int tmp_int = atoi(shuzi_str_zheng.c_str());
printf("-->tmp_int:%d;-->shuzi_str_zheng.c_str():%s;\n", tmp_int, shuzi_str_zheng.c_str());
}


{
string shuzi_str_zheng = "+123";
int tmp_int = atoi(shuzi_str_zheng.c_str());
printf("-->tmp_int:%d;-->shuzi_str_zheng.c_str():%s;\n", tmp_int, shuzi_str_zheng.c_str());
}
{
cout << "测试:"<< ++i << endl;
string shuzi_str_zheng = "+123";
int tmp_int = atoi(shuzi_str_zheng.c_str());
printf("-->shuzi_str_zheng.c_str():%s;-->tmp_int:%d;\n", shuzi_str_zheng.c_str(), tmp_int);


shuzi_str_zheng += '5';


tmp_int = atoi(shuzi_str_zheng.c_str());
printf("-->shuzi_str_zheng.c_str():%s;-->tmp_int:%d;\n", shuzi_str_zheng.c_str(), tmp_int);
}


{
cout << "测试:" << ++i << endl;
string shuzi_str_zheng = "+123A";
int tmp_int = atoi(shuzi_str_zheng.c_str());
printf("-->shuzi_str_zheng.c_str():%s;-->tmp_int:%d;\n", shuzi_str_zheng.c_str(), tmp_int);


shuzi_str_zheng += '5';


tmp_int = atoi(shuzi_str_zheng.c_str());
printf("-->shuzi_str_zheng.c_str():%s;-->tmp_int:%d;\n", shuzi_str_zheng.c_str(), tmp_int);
}


{
cout << "测试:" << ++i << endl;
int j = 0;
vector<int> vec;
int a = ++j;
vec.push_back(a);


a = ++j;
vec.push_back(a);


a = ++j;
vec.push_back(a);


a = ++j;
vec.push_back(a);


a = ++j;
vec.push_back(a);


cout << "vec size:" << vec.size() << endl;


vector<int>::iterator it;
for(it = vec.begin(); it != vec.end(); it++)

{
cout << *it << endl;
}


vec.insert(vec.begin(),0);


cout << "插入0后:" << endl;
for (it = vec.begin(); it != vec.end(); it++)


{
cout << *it << endl;
}


cout <<"删除1" << endl;
int idx = 0;
for (it = vec.begin(); it != vec.end(); it++, idx++)


{


cout << *it << endl;
if (1 == *it){
vec.erase(vec.begin() + idx);
cout << "删除1" << endl;
break;
}


}


cout << "删除1后遍历向量:" << endl;
for (it = vec.begin(); it != vec.end(); it++)


{
cout << *it << endl;
}


}


{
cout << "测试:" << ++i << endl;
int j = 0;
vector<double> vec;
double a = ++j + 3.1415926;
vec.push_back(a);


a = ++j + 3.1415926;
vec.push_back(a);


a = ++j + 3.1415926;
vec.push_back(a);


a = ++j + 3.1415926;
vec.push_back(a);


a = ++j + 3.1415926;
vec.push_back(a);


cout << "vec size:" << vec.size() << endl;


vector<double>::iterator it;
for (it = vec.begin(); it != vec.end(); it++)


{
cout << *it << endl;
}


}
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值