Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > stl 使用例子
【标  题】:stl 使用例子
【关键字】:stl
【来  源】:http://blog.csdn.net/i_like_cpp/archive/2007/01/13/1482209.aspx

stl 使用例子

Your Ad Here

// fstream02.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
#include <map>

void main()
{
 std::istringstream str1(".88aaaaaaaaaaaaaa.");
 std::cout << str1.str() << std::endl;
 // 显示: .88aaaaaaaaaaaaaa.
 char ch;
 str1 >> ch;
 std::cout << ch << std::endl;
 // 显示: .
 std::cout << str1.tellg() << std::endl;
 // 显示: 1
 int n1;
 str1 >> n1;
 std::cout << n1 << std::endl;
 // 显示: 88
 std::cout << str1.tellg() << std::endl;
 // 显示: 3
 str1 >> ch;
 std::cout << ch << std::endl;
 // 显示: a
 std::cout << str1.tellg() << std::endl;
 // 显示: 4

 std::ostringstream str2;
 str2 << "Hello ";
 str2 << 1000;
 str2 << " Fuck you";
 std::cout << str2.str() << std::endl;
 std::map<std::string, std::string> namemap;
 namemap["岳不群"]="华山派掌门人,人称君子剑";
 namemap["张三丰"]="武当掌门人,太极拳创始人";
 namemap["东方不败"]="第一高手,葵花宝典";

 std::cout << namemap["岳不群"] << std::endl;

 std::map<std::string, std::string>::iterator i = namemap.begin();
 i = namemap.find("岳不群");
 std::cout << i->second << std::endl;
 if(namemap.find("岳不群") != namemap.end())
 {
  std::cout << "Found" << std::endl;
 }
 std::map<std::string, std::string>::iterator b = namemap.begin();
 for (; b != namemap.end(); b++)
  std::cout << b->first << std::endl;

位段结构:【上一篇】
最近编程的一点心得:【下一篇】
【相关文章】
  • STL 相关
  • STL 中文站 http://www.stlchina.org/
  • [STL] 循环中erase
  • STL-有关list元素为结构体,而按其中一元素排序问题
  • Java-JSTL(JSP标准标签库)
  • Win32.LostLove 病毒分析及清除
  • 改写JSTL标签
  • _IsPtrType -- STL type checking on compile-time -- Substitution Failure Is Not An Error (SFINAE)
  • STL六大组件
  • stl入门
  • 【随机文章】
  • Requirements Analysis with 'pseud-Formal' Method
  • AIR-ISA342无线网卡
  • Websphere App Server 6造成磁盘空间不足的一个小bug
  • J2ME优化——if语句优化
  • 通过loadlin.exe引导Linux进行硬盘安装
  • st31055n st31051n st31230n st31200n
  • Cisco路由器配置教程
  • 用设计模式固化你的C#程序(4)
  • unlink.c
  • DNS
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.