Кажется, вам легко, но я застрял здесь. Вот функция в C++ для загрузки матрицы из файла ASCII.не может преобразовать 'const char *' в 'std :: istream *
void load_matrix(std::istream* is,
std::vector< std::vector<double> >* matrix,
const std::string& delim = " \t")
{
using namespace std;
string line;
string strnum;
// clear first
matrix->clear();
// parse line by line
while (getline(*is, line))
{
matrix->push_back(vector<double>());
for (string::const_iterator i = line.begin(); i != line.end(); ++ i)
{
// If we i is not a delim, then append it to strnum
if (delim.find(*i) == string::npos)
{
strnum += *i;
continue;
}
// if strnum is still empty, it means the previous char is also a
// delim (several delims appear together). Ignore this char.
if (strnum.empty())
continue;
// If we reach here, we got a number. Convert it to double.
double number;
istringstream(strnum) >> number;
matrix->back().push_back(number);
strnum.clear();
}
}
}
В коде у меня есть, мы получаем имя файла из пользователя, как показано ниже есть default.dat файл экранного:
const char* filename1 = (argc > 1) ? argv[1] : "default.dat";
Мне интересно, как я могу использовать этот имя_файла1, как argunemt ФОТ функция loadmatrix.
Благодаря
Что случилось с [ 'ifstream :: open'] (http://www.cplusplus.com/reference/fstream/ifstream/open/)? – Till