0

Well, It's pretty hard to explain excatly what I want to I'll just give a example.

{accbeingused0or1}|{accName}|{accPassword}|{gameName}|{gamePassword}

so It'll look like this:

0|account123|password123|gamename123|password123
genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

3

Here you go:

template< char Ch >
std::istream& Char( std::istream& is )
{
    if( (is >> std::ws).get() != Ch )
        is.setstate( std::ios::failbit );

    return is;
}

struct Data
{
    int acc_used;
    std::string accountName;
    std::string accountPassword;
    std::string gameName;
    std::string gamePassword;
};

std::istream& operator>>( std::istream& is, Data& d )
{
    is >> d.acc_used >> Char<'|'> >> std::ws;
    std::getline( is, d.accountName, '|' );    
    std::getline( is, d.accountPassword, '|' ); 
    std::getline( is, d.gameName, '|' ); 
    is >> d.gamePassword;
    return is;
}
Columbo
  • 60,038
  • 8
  • 155
  • 203
  • First of all, Thank you very much for trying to help me. I've been trying to get it working with your code for about an hour now but I'm stuck and I don't know what to do. Can you give me maybe a little bit more support on how to do it excatly like: Put it in a loop/class, Open the file: current.txt, Then put everything in a buffer (acc_used, accountName, accountPassword, gameName, gamePassword) Also, I'm sorry for being so dumb to this. I'm pretty new to coding, but you probably already realised it :P – user3699124 Jun 02 '14 at 13:03
  • 1
    nvm, I figured it out! Thank you very much the code really helped me – user3699124 Jun 02 '14 at 14:09
  • Sorry! There was a typo in the code, fixed it. Glad it helped you, sorry i couldn't reply earlier :// – Columbo Jun 02 '14 at 14:27
  • Relevent: http://stackoverflow.com/questions/9825768/safer-but-easy-to-use-and-flexible-c-alternative-to-sscanf/9832875#9832875 – Mooing Duck Jun 02 '14 at 21:37