[BOOST]学习使用点滴-1-字符处理[by galphy]

[20050120]
 1.字符转换
 1.1 相关类
   lexical_cast
   bad_lexical_cast
 1.2 定义文件#include <boost/lexical_cast.hpp>
 1.3 功能简介

   用来进行类型转换的,字符串与数值之间的转换
 1.4 使用举例:
  Eclipse 3.0, GUN G++ , Winxp测试通过。
  #include <iostream>
  #include <boost/lexical_cast.hpp>

  using namespace std;

  main()
  {
   int i=100;
   char* pstr = "10101";
 
   cout<<"Before convert i is:"<<i<<endl;
   i = boost::lexical_cast< int >(pstr);
   cout<<"After convert i is:"<<i<<endl;
 
   return 0;
  }
  //print: Before convert i is:100
  //     After convert i is:10101
 
 1.5 其他:
  转换的异常处理和一般的异常处理相同。
  如:try
        {
            //进行转换
        }
        catch(bad_lexical_cast &)
        {
            //处理异常
        }
   
 2.格式化字符串
 2.1 相关类
   format
 2.2 定义文件:#include <boost/format.hpp>
 2.3 功能简介:
   构建一个格式化的字符串,其中的某些字符是待定的,其可以以参数的形式写入。
 2.4 使用举例:
    Eclipse 3.0, GUN G++ , Winxp测试通过。
    #include <iostream>
    #include <boost/format.hpp>
    #include <string>

    using namespace std;
  
    using boost::format;
    using boost::io::group;
    int main()
    {
         format fmt("%1% %2% %3% %4% %5% %6%/n");
         //使用%1%进行参数替换,1代表第一个参数
         string str;
         int i=100;
         cout<<fmt  % 'g' % 'a' % 'l' % 'p' % 'h' % 'y'<<endl;
         //%操作符压入参数
         string s_tmp =boost::str(fmt);
         //str()自由函数,fomat->string
         //同样也可使用format.str();

         cout << s_tmp;
         return 0;
    }
 2.5 格式说明:
    “$“的使用:后面加printf的格式控制符
    “|“的使用:简化printf的格式控制符
    1.无参数顺序:
        format(“%5d %4s %5f“); //%后面直接加printf的格式控制符,参数顺序传入
        format(“%|5| %|4| %|5|);//效果同上,自动判断d,s,f等控制符号
    2.有参数顺序:
        format(“%1% %2% %1%“); 
        format(“%1$5d  %2$5s %1$5d);
        format(“%|1$5|  %|2$5| %|1$5|);//效果同上,自动判断d,s,f等控制符号
    3.具体格式:

        [ N$ ] [ flags ] [ 宽度] [ . 精度] type-char
                    

  • FlagMeaningeffect on internal stream
    '-'left alignmentN/A (applied later on the string)
    '='centered alignmentN/A (applied later on the string)
    - note : added feature, not in printf -
    '_'internal alignmentsets internal alignment
    - note : added feature, not in printf -
    '+'show sign even for positive numberssets showpos
    '#'show numerical base, and decimal pointsets showbase and showpoint
    '0'pad with 0's (inserted after sign or base indicator)if not left-aligned, calls setfill('0') and sets internal
    Extra actions are taken after stream conversion to handle user-defined output.
    ' 'if the string does not begin with + or -, insert a space before the converted stringN/A (applied later on the string)
    Different to printf's behaviour : it is not affected by internal alignment
  • Type-CharMeaningeffect on stream
    p or xhexadecimal outputsets hex
    ooctal outputsets oct
    escientific float formatsets floatfield bits to scientific
    ffixed float formatsets floatfield bits to fixed
    ggeneral -default- float formatunset all floatfield bits
    X, E or Gsame effect as their lowercase counterparts, but using uppercase letters for number outputs. (exponents, hex digits, ..)same effects as 'x', 'e', or 'g', plus uppercase
    d, i or udecimal type outputsets basefield bits to dec
    s or Sstring outputprecision specification is unset, and its value goes to an internal field for later 'truncation'. (see precision explanation above)
    c or C1-character outputonly the first character of the conversion string is used.
    %print the character %N/A




            
源码地址: https://pan.quark.cn/s/3916362e5d0a 在C#编程平台下,构建一个曲线编辑器是一项融合了图形用户界面(GUI)构建、数据管理及数学运算的应用开发任务。 接下来将系统性地介绍这个曲线编辑器开发过程中的核心知识点:1. **定制曲线面板展示数据曲线**: - 控件选用:在C#的Windows Forms或WPF框架中,有多种控件可用于曲线呈现,例如PictureBox或用户自定义的UserControl。 通过处理重绘事件,借助Graphics对象执行绘图动作,如运用DrawCurve方法。 - 数据图形化:通过线性或贝塞尔曲线连接数据点,以呈现数据演变态势。 这要求掌握直线与曲线的数学描述,例如两点间的直线公式、三次贝塞尔曲线等。 - 坐标系统与缩放比例:构建X轴和Y轴,设定坐标标记,并开发缩放功能,使用户可察看不同区间内的数据。 2. **在时间轴上配置多个关键帧数据**: - 时间轴构建:开发一个时间轴组件,显示时间单位刻度,并允许用户在特定时间点设置关键帧。 时间可表现为连续形式或离散形式,关键帧对应于时间轴上的标识。 - 关键帧维护:利用数据结构(例如List或Dictionary)保存关键帧,涵盖时间戳和关联值。 需考虑关键帧的添加、移除及调整位置功能。 3. **调整关键帧数据,通过插值方法获得曲线**: - 插值方法:依据关键帧信息,选用插值方法(如线性插值、样条插值,特别是Catmull-Rom样条)生成平滑曲线。 这涉及数学运算,确保曲线在关键帧之间无缝衔接。 - 即时反馈:在编辑关键帧时,即时刷新曲线显示,优化用户体验。 4. **曲线数据的输出**: - 文件类型:挑选适宜的文件格式存储数据,例如XML、JSON或...
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值