2012-12-25 3 views
8

"AAPL"을 엑셀 시트에 입력하고 해당 값을 반환하는 현재 코드가 있습니다.문자열을 C++의 변형으로 변환합니다.

내가 cout << "Ticker: "; 후 내가 (예 : AAPL 등) 종목 코드를 입력 할 수 있도록 그것을 만들 내가 string를 사용하여 그렇게 시도 variant_t ticker = "xxx".로 사용하지만 난 'std::string to const _variant_t &'에서 변환 할 수 없습니다라는 오류 싶습니다

이 작업을 수행 할 여지가 있습니까? 미리 감사드립니다.

XL->Workbooks->Open(L"F:\\xxx\\Desktop\\fxxxx.xlsx"); 
Excel::RangePtr pRange = pSheet->Cells; 

cout << "Ticker: "; 
variant_t ticker = "AAPL"; 

pRange->Item[2][1] = ticker; 
double value = pRange->Item[2][2]; 
cout << "\n Value = " << value << endl; 

답변

6

ticker.SetString(str.c_str())으로 전화하십시오.

은 참조 : 여기 http://msdn.microsoft.com/en-us/library/x295h94e%28v=vs.100%29.aspx

+0

감사합니다,하지만 오류가 발생, 정확히 내가 넣어 어디 어디에 ? – user1594369

+0

'variant_t ticker;와'pRange-> Item .. = ticker;'사이의 어딘가에 있습니다. 물론'str'은 std :: string 입력이 무엇이든지간에 호출되어야합니다. 그리고 문자열을 읽은 후이를 수행하기를 원하거나 올바른 결과를 얻지 못할 것입니다. ;) –

+0

답변을 "답변"으로 추가하여 (코드를 훨씬 쉽게 읽을 수있게 할 수 있습니다.) 내가 도움을받을 수 있다고 생각하면 내 대답을 "수락"합니다. –

2

이 작업 코드입니다 : 당신의 도움을 많이, 나는 여러 라인이 추가 시도

XL->Workbooks->Open(L"F:\\xx\\Desktop\\xxz.xlsx");        //Open databse 
    Excel::_WorksheetPtr pSheet = XL->ActiveSheet;          //Point to Active Sheet 
    Excel::RangePtr pRange = pSheet->Cells;            //Point to Active Cells 
    cout << " Ticker: ";                //Prompt Ticker 
    string tick;                  //Define string "tick" to store ticker 
    cin >> tick;                  //Store ticker 
    variant_t ticker;                 //Define variant to be used for ticker 
    ticker.SetString(tick.c_str());              //Convert string to variant         
    pRange->Item[2][1] = ticker;              //Write ticker to cell 
    double bi = pRange->Item[2][2];              //Read Beta, store as "bi" 
    cout << "\n Beta = " << bi << endl;             //Return Value 
    XL->Application->Quit(); 
관련 문제