asdf
asdf

Reputation: 1475

fstream reading misstake

guys im desperate and i really dont know what i am doing wrong :( I just wanna get my program to simply add "hello" in the file read it and print it; The writing works well but for some reasone he is not reading it out of the file again (at method list...

    #include "user.h"
#include <string>

using namespace std;

user::user(string aaa)
{
    name=aaa;
    log.open(name.c_str(), ios::in|ios::out | ios::trunc);
    log<<flush;

}

void user::insert(string to, string message)
{
    log.write("hallo",5);
}

void user::list(){
   string mylist;
//    getline("nicht hallo",list);
   getline(log,mylist);
    cout<<mylist;
}

user::~user()
{
    log.close();//dtor
}

Upvotes: 1

Views: 141

Answers (1)

asdf
asdf

Reputation: 1475

You have to set the filepointer to the beginning before reading

log.seekg(0, std::ios::beg);

Upvotes: 1

Related Questions