C++ writing object data to fileWriting structured file in C++Writing/reading data structure to a file using C++Reading and writing binary data in C++Writing binary data to file in LinuxDataStream interface for reading and writing dataWriting waypoints to a fileObject-oriented purchase data structureProcessing XYZ data from a large fileRead a Person object from file streamGenerate HTML file from Handlebars template and data object

Review your own paper in Mathematics

Grepping string, but include all non-blank lines following each grep match

Why is the sun approximated as a black body at ~ 5800 K?

Typing CO_2 easily

Sigmoid with a slope but no asymptotes?

How to leave product feedback on macOS?

How can ruler support inventing of useful things?

Giving feedback to someone without sounding prejudiced

If the only attacker is removed from combat, is a creature still counted as having attacked this turn?

How much do grades matter for a future academia position?

Can I cause damage to electrical appliances by unplugging them when they are turned on?

How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?

Is there anyway, I can have two passwords for my wi-fi

Sound waves in different octaves

Can I say "fingers" when referring to toes?

How to write Quadratic equation with negative coefficient

Check if object is null and return null

Deciphering cause of death?

Origin of pigs as a species

Would this string work as string?

When and why was runway 07/25 at Kai Tak removed?

Did I make a mistake by ccing email to boss to others?

How do I tell my boss that I'm quitting in 15 days (a colleague left this week)

What is this high flying aircraft over Pennsylvania?



C++ writing object data to file


Writing structured file in C++Writing/reading data structure to a file using C++Reading and writing binary data in C++Writing binary data to file in LinuxDataStream interface for reading and writing dataWriting waypoints to a fileObject-oriented purchase data structureProcessing XYZ data from a large fileRead a Person object from file streamGenerate HTML file from Handlebars template and data object













0












$begingroup$


I'm trying to write a program that stores usernames and passwords. So I have created a Record class. Each record has an id, title, username, and password field. I want to write each record to a text file.



However, I am having some issues. When I compile I get the following errors.



'Record::getTitle': non-standard syntax; use '&' to create a pointer to member
'Record::getUsername': non-standard syntax; use '&' to create a pointer to member
'Record::getPassword': non-standard syntax; use '&' to create a pointer to member


The problem:



writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);


The getTitle(and others) return a string. So I am not sure why this isn't working. Any suggestions would be appreciated.



Complete code (so far) below..



#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <functional>
using namespace std;

string GetInput();
void MainMenu();
void Title();
void AddRecord();
void writeToFile(string title, string username, string password);

class Record

private:

string id;
string title;
string username;
string password;
static int numberOfRecords;

public:

void setTitle(string title)
this->title = title;

string getTitle()
return title;


void setUsername(string username)
this->username = username;

string getUsername()
return username;


void setPassword(string password)
this->password = password;

string getPassword()
return password;


static int GetNumberOfRecords()
return numberOfRecords;

;

struct MenuAction

string description;
function<void()> action;
;

static const map <string, MenuAction> actionTable

"1", "Add entry", []() AddRecord(); ,
"2", "Edit entry", []() cout << "Edit entry" << "n"; ,
"q", "Quit", []() cout << "Quit" << "n";
;

int main()

Title();
MainMenu();

return 0;


void Title() Database

void MainMenu()

for (auto const& x : actionTable)
cout << x.first << ". " << (x.second).description << "n";


string input;

while (actionTable.count(input) == 0)
input = GetInput();


actionTable.at(input).action();


void AddRecord()

cout << "============= Add Record ============" << endl << endl;

string id;
string title;
string username;
string password;

cout << "Title: ";
getline(cin, title);
cout << "Username: ";
getline(cin, username);
cout << "Password: ";
getline(cin, password);

Record firstRecord;
firstRecord.setTitle(title);
firstRecord.setUsername(username);
firstRecord.setPassword(password);

writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);


string GetInput()

string s = "";

cout << ">> ";
getline(cin, s);

return s;


void writeToFile(string title, string username, string password)

ofstream outFile;

outFile.open("database.txt", ios_base::app);
outFile << title << "t" << username << "t" << password << "n";

cout << "============= Record Added To Database ============" << endl;



Feel free to comment or nag other portions of my code :)










share|improve this question







New contributor




okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$
















    0












    $begingroup$


    I'm trying to write a program that stores usernames and passwords. So I have created a Record class. Each record has an id, title, username, and password field. I want to write each record to a text file.



    However, I am having some issues. When I compile I get the following errors.



    'Record::getTitle': non-standard syntax; use '&' to create a pointer to member
    'Record::getUsername': non-standard syntax; use '&' to create a pointer to member
    'Record::getPassword': non-standard syntax; use '&' to create a pointer to member


    The problem:



    writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);


    The getTitle(and others) return a string. So I am not sure why this isn't working. Any suggestions would be appreciated.



    Complete code (so far) below..



    #include <iostream>
    #include <string>
    #include <fstream>
    #include <map>
    #include <functional>
    using namespace std;

    string GetInput();
    void MainMenu();
    void Title();
    void AddRecord();
    void writeToFile(string title, string username, string password);

    class Record

    private:

    string id;
    string title;
    string username;
    string password;
    static int numberOfRecords;

    public:

    void setTitle(string title)
    this->title = title;

    string getTitle()
    return title;


    void setUsername(string username)
    this->username = username;

    string getUsername()
    return username;


    void setPassword(string password)
    this->password = password;

    string getPassword()
    return password;


    static int GetNumberOfRecords()
    return numberOfRecords;

    ;

    struct MenuAction

    string description;
    function<void()> action;
    ;

    static const map <string, MenuAction> actionTable

    "1", "Add entry", []() AddRecord(); ,
    "2", "Edit entry", []() cout << "Edit entry" << "n"; ,
    "q", "Quit", []() cout << "Quit" << "n";
    ;

    int main()

    Title();
    MainMenu();

    return 0;


    void Title() Database

    void MainMenu()

    for (auto const& x : actionTable)
    cout << x.first << ". " << (x.second).description << "n";


    string input;

    while (actionTable.count(input) == 0)
    input = GetInput();


    actionTable.at(input).action();


    void AddRecord()

    cout << "============= Add Record ============" << endl << endl;

    string id;
    string title;
    string username;
    string password;

    cout << "Title: ";
    getline(cin, title);
    cout << "Username: ";
    getline(cin, username);
    cout << "Password: ";
    getline(cin, password);

    Record firstRecord;
    firstRecord.setTitle(title);
    firstRecord.setUsername(username);
    firstRecord.setPassword(password);

    writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);


    string GetInput()

    string s = "";

    cout << ">> ";
    getline(cin, s);

    return s;


    void writeToFile(string title, string username, string password)

    ofstream outFile;

    outFile.open("database.txt", ios_base::app);
    outFile << title << "t" << username << "t" << password << "n";

    cout << "============= Record Added To Database ============" << endl;



    Feel free to comment or nag other portions of my code :)










    share|improve this question







    New contributor




    okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      0












      0








      0





      $begingroup$


      I'm trying to write a program that stores usernames and passwords. So I have created a Record class. Each record has an id, title, username, and password field. I want to write each record to a text file.



      However, I am having some issues. When I compile I get the following errors.



      'Record::getTitle': non-standard syntax; use '&' to create a pointer to member
      'Record::getUsername': non-standard syntax; use '&' to create a pointer to member
      'Record::getPassword': non-standard syntax; use '&' to create a pointer to member


      The problem:



      writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);


      The getTitle(and others) return a string. So I am not sure why this isn't working. Any suggestions would be appreciated.



      Complete code (so far) below..



      #include <iostream>
      #include <string>
      #include <fstream>
      #include <map>
      #include <functional>
      using namespace std;

      string GetInput();
      void MainMenu();
      void Title();
      void AddRecord();
      void writeToFile(string title, string username, string password);

      class Record

      private:

      string id;
      string title;
      string username;
      string password;
      static int numberOfRecords;

      public:

      void setTitle(string title)
      this->title = title;

      string getTitle()
      return title;


      void setUsername(string username)
      this->username = username;

      string getUsername()
      return username;


      void setPassword(string password)
      this->password = password;

      string getPassword()
      return password;


      static int GetNumberOfRecords()
      return numberOfRecords;

      ;

      struct MenuAction

      string description;
      function<void()> action;
      ;

      static const map <string, MenuAction> actionTable

      "1", "Add entry", []() AddRecord(); ,
      "2", "Edit entry", []() cout << "Edit entry" << "n"; ,
      "q", "Quit", []() cout << "Quit" << "n";
      ;

      int main()

      Title();
      MainMenu();

      return 0;


      void Title() Database

      void MainMenu()

      for (auto const& x : actionTable)
      cout << x.first << ". " << (x.second).description << "n";


      string input;

      while (actionTable.count(input) == 0)
      input = GetInput();


      actionTable.at(input).action();


      void AddRecord()

      cout << "============= Add Record ============" << endl << endl;

      string id;
      string title;
      string username;
      string password;

      cout << "Title: ";
      getline(cin, title);
      cout << "Username: ";
      getline(cin, username);
      cout << "Password: ";
      getline(cin, password);

      Record firstRecord;
      firstRecord.setTitle(title);
      firstRecord.setUsername(username);
      firstRecord.setPassword(password);

      writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);


      string GetInput()

      string s = "";

      cout << ">> ";
      getline(cin, s);

      return s;


      void writeToFile(string title, string username, string password)

      ofstream outFile;

      outFile.open("database.txt", ios_base::app);
      outFile << title << "t" << username << "t" << password << "n";

      cout << "============= Record Added To Database ============" << endl;



      Feel free to comment or nag other portions of my code :)










      share|improve this question







      New contributor




      okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I'm trying to write a program that stores usernames and passwords. So I have created a Record class. Each record has an id, title, username, and password field. I want to write each record to a text file.



      However, I am having some issues. When I compile I get the following errors.



      'Record::getTitle': non-standard syntax; use '&' to create a pointer to member
      'Record::getUsername': non-standard syntax; use '&' to create a pointer to member
      'Record::getPassword': non-standard syntax; use '&' to create a pointer to member


      The problem:



      writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);


      The getTitle(and others) return a string. So I am not sure why this isn't working. Any suggestions would be appreciated.



      Complete code (so far) below..



      #include <iostream>
      #include <string>
      #include <fstream>
      #include <map>
      #include <functional>
      using namespace std;

      string GetInput();
      void MainMenu();
      void Title();
      void AddRecord();
      void writeToFile(string title, string username, string password);

      class Record

      private:

      string id;
      string title;
      string username;
      string password;
      static int numberOfRecords;

      public:

      void setTitle(string title)
      this->title = title;

      string getTitle()
      return title;


      void setUsername(string username)
      this->username = username;

      string getUsername()
      return username;


      void setPassword(string password)
      this->password = password;

      string getPassword()
      return password;


      static int GetNumberOfRecords()
      return numberOfRecords;

      ;

      struct MenuAction

      string description;
      function<void()> action;
      ;

      static const map <string, MenuAction> actionTable

      "1", "Add entry", []() AddRecord(); ,
      "2", "Edit entry", []() cout << "Edit entry" << "n"; ,
      "q", "Quit", []() cout << "Quit" << "n";
      ;

      int main()

      Title();
      MainMenu();

      return 0;


      void Title() Database

      void MainMenu()

      for (auto const& x : actionTable)
      cout << x.first << ". " << (x.second).description << "n";


      string input;

      while (actionTable.count(input) == 0)
      input = GetInput();


      actionTable.at(input).action();


      void AddRecord()

      cout << "============= Add Record ============" << endl << endl;

      string id;
      string title;
      string username;
      string password;

      cout << "Title: ";
      getline(cin, title);
      cout << "Username: ";
      getline(cin, username);
      cout << "Password: ";
      getline(cin, password);

      Record firstRecord;
      firstRecord.setTitle(title);
      firstRecord.setUsername(username);
      firstRecord.setPassword(password);

      writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);


      string GetInput()

      string s = "";

      cout << ">> ";
      getline(cin, s);

      return s;


      void writeToFile(string title, string username, string password)

      ofstream outFile;

      outFile.open("database.txt", ios_base::app);
      outFile << title << "t" << username << "t" << password << "n";

      cout << "============= Record Added To Database ============" << endl;



      Feel free to comment or nag other portions of my code :)







      c++ beginner object-oriented






      share|improve this question







      New contributor




      okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 15 mins ago









      okkv1747vmokkv1747vm

      183




      183




      New contributor




      okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      okkv1747vm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          okkv1747vm is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215890%2fc-writing-object-data-to-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          okkv1747vm is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          okkv1747vm is a new contributor. Be nice, and check out our Code of Conduct.












          okkv1747vm is a new contributor. Be nice, and check out our Code of Conduct.











          okkv1747vm is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215890%2fc-writing-object-data-to-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Why is a white electrical wire connected to 2 black wires?How to wire a light fixture with 3 white wires in box?How should I wire a ceiling fan when there's only three wires in the box?Two white, two black, two ground, and red wire in ceiling box connected to switchWhy is there a white wire connected to multiple black wires in my light box?How to wire a light with two white wires and one black wireReplace light switch connected to a power outlet with dimmer - two black wires to one black and redHow to wire a light with multiple black/white/green wires from the ceiling?Ceiling box has 2 black and white wires but fan/ light only has 1 of eachWhy neutral wire connected to load wire?Switch with 2 black, 2 white, 2 ground and 1 red wire connected to ceiling light and a receptacle?

          कुँवर स्रोत दिक्चालन सूची"कुँवर""राणा कुँवरके वंशावली"

          सि.चक भराडी, कोश्याँकुटोली तहसील इन्हें भी देखें बाहरी कड़ियाँ दिक्चालन सूची(निर्देशांक ढूँढें)www.uttara.gov.inउत्तराखण्ड - भारत सरकार के आधिकारिक पोर्टल परउत्तराखण्ड सरकार का आधिकारिक जालपृष्ठउत्तराखण्डउत्तरा कृषि प्रभासंबढ़ाने मेंसं