zoukankan      html  css  js  c++  java
  • Extract String From Text 1.0

     main.cpp

     1 #include <iostream>
     2 #include <stdlib.h>
     3 #include <fstream>
     4 #include <string>
     5 
     6 using namespace std;
     7 
     8 string readLine ( const char* filepath ) {
     9     ifstream file;
    10     file.open ( filepath );
    11     string text;
    12     if ( file.is_open() ) {
    13         while ( !file.eof() ) {
    14             getline ( file, text );
    15             break;
    16         }
    17     }
    18     file.close();
    19     return text;
    20 }
    21 
    22 int main ( int argc, char* argv[] ) {
    23     string opt = argv[1];
    24     if ( !opt.compare ( "-p" ) ) {
    25         string text = readLine ( argv[3] );
    26         size_t found = text.find ( argv[2] );
    27         if ( found != string::npos ) {
    28             cout << found << endl;
    29             return 0;
    30         }
    31     } else if ( !opt.compare ( "-e" ) ) {
    32         string text = readLine ( argv[4] );
    33         cout << text.substr ( atoi ( argv[2] ), atoi ( argv[3] ) ) << endl;
    34         return 0;
    35     }
    36     return -1;
    37 }

    附件1

  • 相关阅读:
    Js Array 删除
    语音播报功能
    js实现HashTable
    Js 克隆
    获取电脑名和IP地址
    获取电脑名和Ip
    IIS 配置问题
    WCF 服务
    【并查集】wikioi1001舒适的路线
    【实用】读取信息
  • 原文地址:https://www.cnblogs.com/rms365/p/10934058.html
Copyright © 2011-2022 走看看