0

I've been trying my best to solve a little problem I have but am struggling to find a sensible solution/explanation so I was hoping someone could help?

I have basically created a function which, inside, writes to a file, and I was hoping that outside of this I would be able to open that said file but I get the following error:

Undefined symbol: ReadingAFile(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >)

My codes are as follows:

Function:

void CreatingAFile(int n)
{
    matrix_Struct matrix_A;
    matrix_A.value = n;
    matrix_A.symmetric = 1;

    std::ofstream writeFile;
    writeFile.open("fileToOpen.dat");
    assert(writeFile.is_open());
   
    writeFile << "Symmetry" << "\n";
    writeFile << matrix_A.symmetric << "\n";
    writeFile << "Number to Iterate";
    writeFile << matrix_A.value << "\n";
}

My main:

int main()
{
    CreatingAFile(3);
    csr_matrix file3 = ReadingAFile("fileToOpen.dat");
}

where ReadingAFile is a file from another header of mine, that runs perfectly fine - it has a function prototype:

matrix_Struct ReadingAFile(std::string nameOfFile);
learning
  • 11
  • 2
  • Where does the definition for `ReadingAFile` live? In the header file as well? – JohnFilleau Nov 28 '21 at 18:19
  • @JohnFilleau Yes! So, it's in another .cpp's header file but I have added it into this new header file with #include "thefile.cpp" :) – learning Nov 28 '21 at 18:51
  • And how are you compiling your project? Do you know the preprocessor, compilation, and linking steps of project building? – JohnFilleau Nov 28 '21 at 18:52
  • Also, look at the linked question/answer. – JohnFilleau Nov 28 '21 at 18:52
  • @JohnFilleau I use Xcode so i literally just tap the play button and it builds and compiles automatically - I don't have to use any g++ or /a.out things that I think some softwares use? – learning Nov 28 '21 at 18:54

0 Answers0