string 总结
来源:互联网 发布:sql 恢复数据库 编辑:程序博客网 时间:2024/05/29 05:04
void string_replace(string & bigstr,const string &srcstr,const string& decstr)
{
string::size_type pos = 0;
string::size_type strlen =srcstr.size();
string::size_type declen =decstr.size();
while( (pos= bigstr.find(srcstr,pos)) != string::npos)
{
bigstr.replace(pos,strlen +5,decstr); // 这个是用decstr 代替多少个字符,无论多少个字符,换成的都是decstr。
pos += declen;
}
}
#ifdef _FINDFIRST_
const string str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
void main(void)
{
string str2="/*------------jing ---- peng */";
string::size_type pos = str2.find_first_of(str);
if ( pos == string::npos)
{
cout<<"not find the str"<<endl;
}
string::size_type endpos = str2.find_last_of(str);
if ( endpos == string::npos)
{
cout<<"not find the str at end"<<endl;
}
string str3 = str2.substr(pos,endpos-pos+1 );
cout<<str3<<endl;
getch();
}
int string2int(const string & str)
{
return atoi(str.c_str());
}
double string2double(const string & str)
{
return atof(str.c_str());
}
#include <iostream>
#include <sstream>
#include <string>
template <class T>
void convertFromString(T &, const std::string &);
int main()
{
std::string s("123");
// Convert std::string to int
int i = 0;
convertFromString(i,s);
std::cout << i << std::endl;
// Convert std::string to double
double d = 0;
convertFromString(d,s);
std::cout << d << std::endl;
return 0;
}
template <class T>
void convertFromString(T &value, const std::string &s)
{
std::stringstream ss(s);
ss >> value;
}
#endif
- String总结
- string 总结
- String总结
- String总结
- string总结
- String总结
- String 总结
- string总结
- String总结(一)String
- STD:string string类总结
- C#-string总结
- string 函数总结
- String类总结
- string 的用法总结
- String分割方法总结
- string 函数总结
- string类总结
- string用法总结
- 转:中国情绪下的“品牌”需求(二)
- 转:中国情绪下的“品牌”需求(一)
- pku 1331 Multiply
- lighttpd1.4.18代码分析
- 【STM32 .Net MF开发板学习-11】步进电机控制(非PWM模式)
- string 总结
- 程序基础设计模式的解析和实现(C++)之二十-Visitor模式
- Java中Native方法
- Fading is true while flowering is past
- 2010-8-2学习轨迹
- pku 1338 Ugly Numbers
- 软盘原理及制作软盘启动盘
- 贝宝开发者挑战赛开幕
- pku 1477 Box of Bricks