青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

牽著老婆滿街逛

嚴以律己,寬以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

兩個 CSV 解析類

其一:
/* Copyright (C) 1999 Lucent Technologies */
/* Excerpted from 'The Practice of Programming' */
/* by Brian W. Kernighan and Rob Pike */

#include 
<iostream>
#include 
<algorithm>
#include 
<string>
#include 
<vector>

using namespace std;

class Csv
{    // read and parse comma-separated values
    
// sample input: "LU",86.25,"11/4/1998","2:19PM",+4.0625

public:
    Csv(istream
& fin = cin, string sep = ",") : 
      fin(fin), fieldsep(sep) 
{}

      
int getline(string&);
      
string getfield(int n);
      
int getnfield() const return nfield; }

private:
    istream
& fin;            // input file pointer
    string line;            // input line
    vector<string> field;    // field strings
    int nfield;                // number of fields
    string fieldsep;        // separator characters

    
int split();
    
int endofline(char);
    
int advplain(const string& line, string& fld, int);
    
int advquoted(const string& line, string& fld, int);
}
;

// endofline: check for and consume \r, \n, \r\n, or EOF
int Csv::endofline(char c)
{
    
int eol;

    eol 
= (c=='\r' || c=='\n');
    
if (c == '\r')
    
{
        fin.
get(c);
        
if (!fin.eof() && c != '\n')
            fin.putback(c);    
// read too far
    }

    
return eol;
}


// getline: get one line, grow as needed
int Csv::getline(string& str)
{    
    
char c;

    
for (line = ""; fin.get(c) && !endofline(c); )
        line 
+= c;
    split();
    str 
= line;
    
return !fin.eof();
}


// split: split line into fields
int Csv::split()
{
    
string fld;
    
int i, j;

    nfield 
= 0;
    
if (line.length() == 0)
        
return 0;
    i 
= 0;

    
do {
        
if (i < line.length() && line[i] == '"')
            j 
= advquoted(line, fld, ++i);    // skip quote
        else
            j 
= advplain(line, fld, i);
        
if (nfield >= field.size())
            field.push_back(fld);
        
else
            field[nfield] 
= fld;
        nfield
++;
        i 
= j + 1;
    }
 while (j < line.length());

    
return nfield;
}


// advquoted: quoted field; return index of next separator
int Csv::advquoted(const string& s, string& fld, int i)
{
    
int j;

    fld 
= "";
    
for (j = i; j < s.length(); j++)
    
{
        
if (s[j] == '"' && s[++j] != '"')
        
{
            
int k = s.find_first_of(fieldsep, j);
            
if (k > s.length())    // no separator found
                k = s.length();
            
for (k -= j; k-- > 0; )
                fld 
+= s[j++];
            
break;
        }

        fld 
+= s[j];
    }

    
return j;
}


// advplain: unquoted field; return index of next separator
int Csv::advplain(const string& s, string& fld, int i)
{
    
int j;

    j 
= s.find_first_of(fieldsep, i); // look for separator
    if (j > s.length())               // none found
        j = s.length();
    fld 
= string(s, i, j-i);
    
return j;
}



// getfield: return n-th field
string Csv::getfield(int n)
{
    
if (n < 0 || n >= nfield)
        
return "";
    
else
        
return field[n];
}


// Csvtest main: test Csv class
int main(void)
{
    
string line;
    Csv csv;

    
while (csv.getline(line) != 0)
    
{
        cout 
<< "line = `" << line <<"'\n";
        
for (int i = 0; i < csv.getnfield(); i++)
            cout 
<< "field[" << i << "] = `"
            
<< csv.getfield(i) << "'\n";
    }

    
return 0;
}




其二:
來源于:http://www.mayukhbose.com/freebies/c-code.php
頭文件:
#ifndef __CSVPARSE_H_2001_06_07__
#define __CSVPARSE_H_2001_06_07__

/*
Copyright (c) 2001, Mayukh Bose
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.  

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name of Mayukh Bose nor the names of other
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include 
<string>
using namespace std;

class CSVParser {
 
private:
  
string m_sData;
  
string::size_type m_nPos;
  
void SkipSpaces(void);
 
public:
  CSVParser();
  
const CSVParser & operator << (const string &sIn);
  
const CSVParser & operator << (const char *sIn);
  CSVParser 
& operator >> (int &nOut);
  CSVParser 
& operator >> (double &nOut);
  CSVParser 
& operator >> (string &sOut);
}
;

#endif

cpp
/*
Copyright (c) 2001, Mayukh Bose
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.  

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name of Mayukh Bose nor the names of other
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include 
<iostream>
#include 
<cstdlib>
#include 
"csvparser.h"
using namespace std;


CSVParser::CSVParser()
{
  m_sData 
= "";
  m_nPos 
= 0;
}


void CSVParser::SkipSpaces(void)
{
  
while (m_nPos < m_sData.length() && m_sData[m_nPos] == ' ')
    m_nPos
++;
}


const CSVParser & CSVParser::operator <<(const string & sIn)
{
  
this->m_sData = sIn;
  
this->m_nPos = 0;
  
return *this;
}


const CSVParser & CSVParser::operator <<(const char *sIn)
{
  
this->m_sData = sIn;
  
this->m_nPos = 0;
  
return *this;
}


CSVParser 
& CSVParser::operator >>(int & nOut)
{
  
string sTmp = "";
  SkipSpaces();
  
while (m_nPos < m_sData.length() && m_sData[m_nPos] != ',')
    sTmp 
+= m_sData[m_nPos++];

  m_nPos
++// skip past comma
  nOut = atoi(sTmp.c_str());
  
return *this;
}


CSVParser 
& CSVParser::operator >>(double & nOut)
{
  
string sTmp = "";
  SkipSpaces();
  
while (m_nPos < m_sData.length() && m_sData[m_nPos] != ',')
    sTmp 
+= m_sData[m_nPos++];

  m_nPos
++// skip past comma
  nOut = atof(sTmp.c_str());
  
return *this;
}


CSVParser 
& CSVParser::operator >>(string & sOut)
{
  
bool bQuotes = false;
  sOut 
= "";
  SkipSpaces();

  
// Jump past first " if necessary
  if (m_nPos < m_sData.length() && m_sData[m_nPos] == '"'{
    bQuotes 
= true;
    m_nPos
++
  }

  
  
while (m_nPos < m_sData.length()) {
    
if (!bQuotes && m_sData[m_nPos] == ',')
      
break;
    
if (bQuotes && m_sData[m_nPos] == '"'{
      
if (m_nPos + 1 >= m_sData.length() - 1)
        
break;
      
if (m_sData[m_nPos+1== ',')
        
break;
    }

    sOut 
+= m_sData[m_nPos++];
  }


  
// Jump past last " if necessary
  if (bQuotes && m_nPos < m_sData.length() && m_sData[m_nPos] == '"')
    m_nPos
++

  
// Jump past , if necessary
  if (m_nPos < m_sData.length() && m_sData[m_nPos] == ',')
    m_nPos
++

  
return *this;
}



posted on 2008-06-03 11:26 楊粼波 閱讀(2330) 評論(1)  編輯 收藏 引用

評論

# re: 兩個 CSV 解析類 2008-10-16 09:49 傲天

這片文章不錯,我喜歡,謝謝博主  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美日韩在线一区| 国产日韩精品在线播放| 亚洲影院免费| 亚洲欧洲日本在线| 亚洲激情在线| 亚洲青涩在线| 午夜亚洲视频| 亚洲尤物视频网| 99热精品在线观看| 99在线热播精品免费| 亚洲午夜免费福利视频| 久久成人免费电影| 欧美国产成人在线| 免费永久网站黄欧美| 欧美1区2区3区| 韩国av一区| 一个色综合av| 亚洲一区免费看| 午夜亚洲视频| 亚洲二区在线观看| 一区二区成人精品| 欧美综合国产| 欧美顶级艳妇交换群宴| 欧美日韩免费一区| 欧美三级视频| 99这里有精品| 中文日韩在线| 免费欧美在线视频| 亚洲性视频h| 欧美一区二区三区视频免费播放 | 午夜精品美女自拍福到在线| 久久久亚洲欧洲日产国码αv| 午夜精品国产更新| 欧美精品在线极品| 悠悠资源网久久精品| 亚洲女同在线| 亚洲精品日本| 国产精品爱久久久久久久| 一本色道久久综合亚洲91| 亚洲高清在线播放| 久久蜜桃资源一区二区老牛| 韩国欧美一区| 免费观看日韩| 国产精品久久久久999| 亚洲精品资源| 欧美综合激情网| 美女黄网久久| 久久久久久自在自线| 韩国av一区| 欧美一区二区视频在线观看| 欧美一区二区三区在线看| 国产亚洲综合精品| 亚洲乱码国产乱码精品精天堂 | 一本色道久久综合亚洲精品按摩 | 欧美大片第1页| 亚洲与欧洲av电影| 午夜日韩视频| 亚洲综合精品自拍| 欧美中文字幕在线观看| 国产欧美亚洲日本| 午夜国产不卡在线观看视频| 性xx色xx综合久久久xx| 亚洲区国产区| 欧美综合第一页| 亚洲一区二区成人在线观看| 欧美专区福利在线| 亚洲性av在线| 嫩草成人www欧美| 亚洲一区二区三区在线播放| 久久在线播放| 欧美日韩国产成人| 美女图片一区二区| 亚洲国产专区校园欧美| 欧美一区午夜视频在线观看| 亚洲精品永久免费精品| 国产麻豆91精品| 国产麻豆91精品| 久久久综合激的五月天| 亚洲综合久久久久| 欧美日韩国产123区| 狼狼综合久久久久综合网 | 亚洲国产婷婷| 蜜臀91精品一区二区三区| 久久久人成影片一区二区三区观看| 在线视频亚洲| 欧美日韩中字| 国产精品99久久久久久宅男| 在线免费观看成人网| 亚洲一区二区精品在线| 99re6这里只有精品视频在线观看| 欧美91大片| 久久久国产成人精品| 国产综合激情| 久久在线免费| 亚洲精品一区二区在线观看| 激情久久综艺| 欧美精品福利在线| 9久草视频在线视频精品| 欧美在线关看| 一区二区三区高清视频在线观看| 一区二区三区精品在线 | 欧美一区二区三区播放老司机| 激情成人在线视频| 欧美电影在线| 一本色道久久综合狠狠躁篇的优点| 在线欧美日韩精品| 欧美一区二区三区在线免费观看 | 中日韩高清电影网| 91久久久一线二线三线品牌| 欧美三级在线| 亚洲网站啪啪| 久久国产精品免费一区| 国产精品一区二区三区乱码 | 欧美专区日韩专区| 在线午夜精品| 久久综合伊人77777| 一本一道久久综合狠狠老精东影业 | 亚洲激情欧美| 亚洲性人人天天夜夜摸| 国产一区二区在线观看免费| 免费成人美女女| 欧美在线视频在线播放完整版免费观看 | 亚洲国产成人午夜在线一区| 午夜影院日韩| 亚洲免费观看高清在线观看| 一本色道久久综合狠狠躁篇怎么玩| 欧美在线999| 一区二区免费在线播放| 欧美风情在线观看| 久久精品视频导航| 久久免费高清视频| 午夜精品久久久久久久99黑人| 欧美不卡三区| 亚洲人成人99网站| 亚洲视频中文字幕| 欧美国产日产韩国视频| 香蕉乱码成人久久天堂爱免费| 午夜欧美精品| 99v久久综合狠狠综合久久| 国产精品网站一区| 韩国av一区二区三区| 伊人久久大香线蕉综合热线| 国产一区二区三区观看| 精品999日本| 国产一区二区久久| 亚洲区一区二| 中日韩视频在线观看| 欧美大片专区| 亚洲色图综合久久| 亚洲网站视频| 久久久久久久尹人综合网亚洲| 久久久国产成人精品| 欧美日韩精品久久| 在线观看亚洲精品视频| 亚洲美女黄色| 久久不射电影网| 亚洲区国产区| 亚洲欧洲一级| 欧美在线视频全部完| 欧美三日本三级三级在线播放| 国产精品自拍网站| 在线性视频日韩欧美| 久久人人97超碰精品888| 亚洲毛片在线免费观看| 久久精品日产第一区二区| 欧美午夜精品久久久久免费视 | 国产精品一二三| 亚洲美女av网站| 欧美aⅴ一区二区三区视频| 亚洲女同在线| 欧美视频中文字幕在线| 亚洲黄色av| 亚洲国产精品久久久久秋霞蜜臀 | 亚洲六月丁香色婷婷综合久久| 先锋影音国产精品| 国产一区二区中文字幕免费看| 亚洲国产欧美不卡在线观看| 中文国产成人精品| 日韩视频免费大全中文字幕| 欧美区视频在线观看| 亚洲图片在线| 一区二区三区高清不卡| 欧美日本韩国一区二区三区| 亚洲免费播放| 夜夜精品视频一区二区| 欧美高清视频一区二区三区在线观看| 亚洲激情视频网站| 亚洲精品乱码| 欧美视频官网| 久久精品欧美日韩精品| 久久青草欧美一区二区三区| 国内精品久久久久久久影视麻豆| 欧美日韩国产免费观看| 99国产精品国产精品久久| 亚洲免费一在线| 国产亚洲欧美一区在线观看 | 亚洲理论在线观看| 亚洲一区免费观看| 亚洲国产三级网| 在线一区二区日韩|