博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

帅得不敢出门

热爱c++ 博客文章多为转载(帖子后面有带原文链接的)以做收藏 若有误处 望多多赐教
   stupidpig.cublog.cn
关于作者  
姓名:帅得不敢出门
职业:学生
年龄:22
位置:福州
C++高手群:3503799
个性介绍:新博客路过也帮推荐下谢谢

我的分类  




入门计划->使用(C++库)istringstream输入(格式化)
//awzzz@2002
//入门计划->使用(C++库)istringstream输入(格式化)
//APO->using istringstream.
//accidence project of using istringstream.(c++ iostream library)

/*
  Reference: http://www.cplusplus.com/ref/iostream/istringstream/

  Description

  istringstream class provides an interface to manipulate strings as if
  they were input streams.

  The objects of this class mantain internally a pointer to a stringbuf
  object that can be obtained/modified by calling member rdbuf. This
  streambuf-derived object stores a sequence of characters (string) that
  can be obtained/modified by calling member str.
*/


//使用(C++库)istringstream输入(格式化)
//simple example

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

void test()
{
    {
        //istringstream iss;
        //iss.str("#123 1.23 aaa ,zzz kk,k oo.jjj");
        istringstream iss("#123 1.23 aaa ,zzz kk,k oo.jjj");
       
        cout << iss.str() << endl;

        char ch;
        iss >> ch;
        cout << ch << endl;

        int i;
        iss >> i;
        cout << i << endl;

        float f;
        iss >> f;
        cout << f << endl;

        char buf[1024];
        iss >> buf;
        cout << buf << endl;

        iss.ignore(100, ',');
        iss >> buf;
        cout << buf << endl;
    }
}

int main(int argc, char* argv[])
{  
    test();
    return 0;
}
输出:
#123 1.23 aaa ,zzz kk,k oo.jjj
#
123
1.23
aaa
zzz
Press any key to continue

 原文地址 http://dev.csdn.net/article/20/20112.shtm
 发表于: 2008-05-23,修改于: 2008-05-23 16:57 已浏览264次,有评论0条 推荐 投诉

  网友评论

  发表评论



Copyright © 2001-2006 ChinaUnix.net All Rights Reserved

感谢所有关心和支持过ChinaUnix的朋友们
页面生成时间:0.02388

京ICP证041476号