Felix Archambault February 2016

Error with fstream library

I simply want to open a file in writing only and put it in a variable there is the error :

Include/FileStream/FileStream.cpp: In function 'void log(std::__cxx11::string)': Include/FileStream/FileStream.cpp:26:5: error: request for member 'close' in 'log', which is of non-class type 'void(std::__cxx11::string) {aka void(std::__cxx11::basic_string<char>)}'  log.close;
     ^ Include/FileStream/FileStream.cpp: In function 'void firstName_read(bool)': Include/FileStream/FileStream.cpp:36:18: error: return-statement with a value, in function returning 'void' [-fpermissive]
           return firstname;
                  ^ Include/FileStream/FileStream.cpp:42:18: error: return-statement with a value, in function returning 'void' [-fpermissive]
           return firstname;

and there is the File that is making trouble :

#include "FileStream.h"
void log(string argument)
{
logFile.open ("log.txt", fstream::out | fstream::app);

logFile << argument;

log.close;
}

void firstName_read (bool boyOrGirl)
{

if (boyOrGirl == true)
     {
          firstname.open("Name/FirstName_Male.txt", fstream::in);

          firstname.close;
          return firstname;
     }
else
     {
          firstname.open("Name/FirstName_Female.txt", fstream::in);
          firstname.close;
          return firstname;

     }
}

Thank you... if you want all the file i have the project hosted on github :

https://github.com/calmunicorn/virtualsociety

Answers


jpo38 February 2016

close is not a ifstream attribute, it's a method. Use firstname.close() to call the function rather than firstname.close.

Additionaly, a void function cannot return a value and also firstname....log.close should also be logFile.close()....there are actually tones of errors in your code.

You may want to start with a simplier piece of code, make it work, and later extend it....


MSalters February 2016

In your function log, the file is named logFile. But you try log.close. That really confuses the compiler; you can't close a function ! Use logfile.close().


MSalters February 2016

void firstName_read( /*...*/ is a function returning nothing aka void. If you want to return a std::string, define it as std::string firstName_read( /*...*/


Felix Archambault February 2016

thank you all of you have helped me fixing the issue now i got some other issues but i will open a new post for that XD

Post Status

Asked in February 2016
Viewed 3,931 times
Voted 5
Answered 4 times

Search




Leave an answer