2014-06-24 5 views
0

으로 변환하는 방법 txt 파일을 구문 분석하고 싶습니다. excel 파일로 작성해야합니다. excel을위한 라이브러리 재미가 있습니다. const char * 파일을 구문 분석하고 데이터를 저장하고 전달하는 데 const char *를 사용합니다. 그 내 코드를 보여주는 벡터 재미의 제공 오류 배역 오류 :벡터를 const char *

#include<iostream> 
#include<string> 
#include<fstream> 
#include<vector> 
#include<sstream> 

using namespace std; 

vector< vector<string> > data; 


void parse(const char* name) 
{ 
    ifstream in(name); 

    string line; 

    // read the file 
    while (getline(in,line,'|')) 
    { 
    vector<string> fields; 
    std::stringstream linestream(line); 
    for (int col = 0 ; col < 21 ; col++) 
    { 
     string f; 
     linestream >> f; 
     fields.push_back(f); 
    } 
    data.push_back(fields); 
    } 

    // output by rows 
    for (vector< vector<string> >::size_type row = 0 ; row < data.size() ; row++) 
    { 
    for (vector<string>::size_type col = 0 ; col < data[row].size() ; col++) 
    { 
    // std::vector<char> copy = data; 
//char * buffer = &copy[0]; 
     /*char *buffer = new char[data.size()]; 
      std::copy(data.begin(), data.end(), buffer);*/ 
     //buffer=static_cast<char *>(data[row]); 
     //cout << buffer[row]; 
     cout << data[row][col]; 

    } 
    cout << endl; 
    } 

    // output by columns 
    /*for (vector<string>::size_type col = 0 ; col < data[0].size() ; col++) 
    { 
    for (vector< vector<string> >::size_type row = 0 ; row < data.size() ; row++) 
    { 
     cout << data[row][col] << ","; 
    } 
    cout << endl; 
    }*/ 
} 

static void example1(const char* path) 
{ 

     sheet->Cell(row, col)->Set(data[r][c]);/i need to pass vector into this fun 
} 


enter code here 

답변

1

data[row][col] 그렇게 data[row][col].c_str()는 당신에게 당신이 찾고있는 const char*을 제공하는 std::string입니다.

그러나 시트가 Excel 시트 COM 개체 인 경우 문자열을 bstr_t 또는 _variant_t에 래핑해야합니다.

사실, Excel 자동화 코드에서 _Worksheet에 Cell 메서드가 표시되지 않습니다.

+0

고맙습니다. – suneetha

+1

@suneetha 제 대답이 당신이 문제를 해결하는 데 도움이된다면, 제 대답을 받아들이는 것이 너무 친절 할 수 있습니다. 이것은 귀하의 질문을 해결 된 것으로 보여주고 약간의 신용을줍니다. 감사. –