Ошибка при создании имени файла объекта Ifstream - PullRequest
0 голосов
/ 08 мая 2018

Есть какая-то конкретная причина, по которой это не получится?

    std::string r = "Hej.whatever";
    std::string const *p = &r;
    std::ifstream file ((*p).c_str(), std::ios::in, std::ios::ate);
    std::ifstream file ((*p), std::ios::in, std::ios::ate);
error: no matching function for call to
  ‘std::basic_ifstream<char>::basic_ifstream(const string&,
               const openmode&, const openmode&)’
  std::ifstream file ((*p), std::ios::in, std::ios::ate);

1 Ответ

0 голосов
/ 08 мая 2018

Вам нужно пройти несколько режимов побитовым ИЛИ (|):

std::ifstream file ((*p), std::ios::in | std::ios::ate);
std::ifstream file2 ((*p), std::ios::in | std::ios::ate);

и вы можете удалить .c_str() из первого звонка, в этом нет необходимости

...