0

I am trying to read the file and store it in an array.

Here's the part of code I am using to open the file:

int readFile(AccessRecord & file, Files & namesIn)
{    
    std::ifstream fin(file.fileName);
    if (fin.fail())
    return -1;
}

this is the new error I am getting when I go to compile:

[meg21allred@LinuxLab08 ~]$ g++ myAssign02.cpp
myAssign02.cpp: In function ‘int readFile(AccessRecord&, Files&)’:
myAssign02.cpp:72:35: error: no matching function for call to

‘std::basic_ifstream<char>::basic_ifstream(std::string&)’
std::ifstream fin(file.fileName);

if I just use std::cout << file.fileName;, it seems to print out the correct fileName but it doesn't like it when I put file.fileName into ifstream line

Swordfish
  • 12,971
  • 3
  • 21
  • 43
Megan
  • 69
  • 4

1 Answers1

1

It looks like you're using a very old compiler that doesn't yet support the ifstream constructor that takes a string, which was added to the C++ standard library in 2011. The old constructor took a const char* (an old-fashioned C-style string), so try:

std::ifstream fin(file.fileName.c_str());
Ross Smith
  • 3,719
  • 1
  • 25
  • 22
  • @Megan Please consider to do some more reseach before asking next time here. Your question has been answered before, and we don't wnt to clutter the FAQ like repository format as it's intended with Stack Overflow. – πάντα ῥεῖ May 05 '19 at 20:46