// 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;
}
//
#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;
}