首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++ 惯用的代码例子(字符倒序,整数合并)3

2012-09-18 
c++ 常用的代码例子(字符倒序,整数合并)3/*cout拆分字符串,装入vector:endlstd::vectorstd::strin

c++ 常用的代码例子(字符倒序,整数合并)3
/*cout<<"拆分字符串,装入vector:"<<endl;
std::vector<std::string>vec;
char ch[]="hello, I love you";
char *p;
p=strtok(ch,",");
while(p!=NULL)
{
vec.push_back(p);
p = strtok (NULL," ,");
}
for(int i= 0; i!=vec.size();++i)
{
cout<<vec[i]<<endl;
}

NullClass obj;
cout<<"空类大小:"<<sizeof(obj)<<endl;*/

    //合并list字符串
/*list <string> first, second;

first.push_back ("a");
first.push_back ("b");

second.push_back ("c");
second.push_back ("d");
second.push_back ("a");
second.push_back ("b");
list<string> str;
merge(first.begin(),first.end(),second.begin(),second.end(),inserter(str,str.begin()));
    for_each(str.begin(), str.end(), PrintStr );*/
    cout<<"//////////////////"<<endl;

//first.merge(second, mycomparison);//less<string>()
/*first.merge(second, less<string>());
for(list<string>::iterator i=first.begin();
i!=first.end(); ++i)
cout<<*i<<endl;*/
   
//整数合并并排序
/*list <int>   myList;
const   int   N=6;
int   A1[N]   =   {1,   3,   5,   7,   9,   11};
int   A2[N]   =   {1,   2,   3,   4,   5,   6};
set <int>   result;
result.insert(14);
merge(A1,A1+N,A2,A2+N,inserter(result,result.begin()));
set<int>::iterator it = result.begin();
while(it != result.end())
{
cout<<*it<<endl;
       it++;
}*/

        cout<<"使用reverse倒序>>"<<endl;
//char s[] = {'a','e','d','f'};
char s[] = "abcdefgjhk";
myreverse(s,sizeof(s)/sizeof(char));//大小为8,从1开始
cout<<"用自定义函数倒序:"<<s<<endl;
reverse(s,s+ sizeof(s)/sizeof(*s)-1);
cout<<"用reverse函数倒序:"<<s<<endl;
   
getchar();
//system("pause");
return 0;
}

热点排行