小编ism*_*sme的帖子

how do i store and get a queue of structure?

How do I store and get value of structure into a queue where I have 2 values? I wanna queue this few values.

| 4 , 2 |

| 3, 5 |

Where by 4,2 and 3,5 can be a variable such as

primaryQ.push(a, b);
Run Code Online (Sandbox Code Playgroud)

My structure:

struct primarytemp{
    double process;
    double secondary;
};
Run Code Online (Sandbox Code Playgroud)

Here's how I declared my main:

int main(){
    queue<primarytemp> primaryQ;
    primaryQ.push(4, 2);
}
Run Code Online (Sandbox Code Playgroud)

c++ queue struct structure

2
推荐指数
1
解决办法
1万
查看次数

替换txt文件中的行c ++

我只是想知道因为我在accounts.txt中有一个包含STATUS:USERID:PASSWORD的文本文件

例如,它看起来像这样:

OPEN:鲍勃:askmehere:

OPEN:约翰:askmethere:

锁定:抢:robmypurse:

我在我的主用户输入,因此用户可以登录3x其他状态将从OPEN更改为LOCK

约翰三次尝试后的例子

之前:

OPEN:鲍勃:askmehere:

OPEN:约翰:askmethere:

锁定:抢:robmypurse:

后:

OPEN:鲍勃:askmehere:

LOCK:约翰:askmethere:

锁定:抢:robmypurse:

我所做的是:

void lockUser(Accounts& in){
// Accounts class consist 3 attributes (string userid, string pass, status)

ofstream oFile;
fstream iFile;
string openFile="accounts.txt";
string status, userid, garbage;
Accounts toupdate;

oFile.open(openFile);
iFile.open(openFile);

    while(!iFile.eof()){

        getline(iFile, status, ':');
        getline(iFile, userid, ':');
        getline(iFile, garbage, '\n');


        if(userid == in.getUserId()){

            toupdate.setUserId(in.getuserId());
            toupdate.setPassword(in.getPassword());
            toupdate.setStatus("LOCK");
            break;
    }

    //here i should update the account.txt how do i do that?
    ofile.open(openFile);

    ofile<<toupdate.getStatus()<<":"<<toupdate.getUserId()":"<<toupdate.getPassword()<<":"<<endl; …
Run Code Online (Sandbox Code Playgroud)

c++ fstream ostream

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×2

fstream ×1

ostream ×1

queue ×1

struct ×1

structure ×1