Visual c++ 如何将向量类型转换为常量字符*
我想解析一个txt文件,该文件应该写在excel文件中我对excel有库乐趣参数采用const char*im使用向量解析文件并存储数据并传递该向量乐趣其给出错误类型转换错误其显示我的代码:Visual c++ 如何将向量类型转换为常量字符*,visual-c++,Visual C++,我想解析一个txt文件,该文件应该写在excel文件中我对excel有库乐趣参数采用const char*im使用向量解析文件并存储数据并传递该向量乐趣其给出错误类型转换错误其显示我的代码: #include<iostream> #include<string> #include<fstream> #include<vector> #include<sstream> using namespace std; vector< v
#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 = ©[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
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
向量<向量>数据;
无效解析(常量字符*名称)
{
输入(名称);
弦线;
//读文件
while(getline(in,line,“|”))
{
向量场;
std::stringstream linestream(行);
for(int col=0;col<21;col++)
{
字符串f;
linestream>>f;
字段。向后推_(f);
}
数据。推回(字段);
}
//按行输出
对于(vector::size_type row=0;row //coutdata[row][col]
是一个std::string
,因此data[row][col].c_str()
为您提供了所需的常量字符*
但如果工作表是Excel工作表COM对象,则需要将字符串包装在bstr\u t或_variant\t中
顺便说一句,在我的Excel自动化代码中,我在工作表中没有看到单元格方法。@suneetha如果我的答案帮助你解决了问题,你可以很乐意接受我的答案。这将显示你的问题已解决,并给我一些信任。谢谢。