zoukankan      html  css  js  c++  java
  • c++之从标准流中提取文本数据

    istream & istream :: get ( char * ,  int ,  char = ' ' ) ;

    istream & istream :: getline ( char * ,  int ,  char = ' ' ) ;

    作用:从文本中提取指定个数的字符,并在串数组末添加一个空字符

    其中,第一个参数指向接受字符数据的字符数组

    第二个参数指定字符数组最多可容纳的字符个数

    第三个参数用于指定一个终止符,缺省为换行符

    操作遇到终止符或提取到规定个数字符时,提取终止

    区别:  get ( ) 不从流中提取终止字符,终止字符仍在输入流中

             getline ( ) 从流中提取终止字符,但终止字符被丢弃

     1 #include<iostream>
     2 using namespace std;
     3 int main ( )
     4 { char  buf [ 80 ] ;
     5    cin.get ( buf , 80 , 'y' ) ;        //指定终止符
     6    cout << buf << endl ;    //默认终止符'
    '
     7    cin.get ( buf , 80 ) ;     
     8    cout << buf << endl ;
     9    cin.getline ( buf , 80 , 'n' ) ;
    10    cout << buf << endl ;
    11    cin.get ( buf , 80 ) ;     
    12    cout << buf << endl ;
    13    return 0;
    14 }
     1 #include<iostream>
     2 #include<fstream>
     3 using namespace std;
     4 int main ( )
     5 { ifstream  inf ( "d:\testnew" ) ;       
     6    char  buf [ 80 ] ;
     7    inf.getline ( buf, 80 ) ;            
     8    cout << buf << "____" << inf.gcount() << endl ;
     9    inf.get( buf, 80 ) ;    
    10    cout << buf << "____" << inf.gcount() << endl ;
    11    inf.close () ;
    12 }
  • 相关阅读:
    最热CPLDFPGA论坛
    DSP Builder开发环境安装
    math.h数学函数库
    (转)Fast Input/Output Registers约束
    用EXCEL去掉最高最低数,网上看到,觉得不错
    GMS6.5.3有0DAY的下载了
    [转]为ArcGIS制作符号
    Total Commander 7.5Beta1的便携版
    关于CAD的一个小发现
    可恶的AP PDF password recovery
  • 原文地址:https://www.cnblogs.com/Smart-Du/p/4338025.html
Copyright © 2011-2022 走看看