🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 168 (from laksa137)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
9 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.3 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue
Last Crawled2026-03-28 17:28:00 (9 days ago)
First Indexed2015-09-27 13:26:00 (10 years ago)
HTTP Status Code200
Meta Titlec++ - Multiple data in a queue | DaniWeb
Meta DescriptionI want to create a queue that holds certain information. I want it to hold multiple peices of information ...
Meta Canonicalnull
Boilerpipe Text
12 Years Ago I want to create a queue that holds certain information. I want it to hold multiple peices of information like below. Name, Age, Race, Sex. How can i create a queue FIFO. that holds multiple pieces of information like this that i can access or add into? Thanks! Dani AI Generated 4 Months Ago Replies from and correctly point to the core idea: group related fields into one item and enqueue that item. For a class-based approach, prefer a compact, value-semantic class (constructor + const accessors) or else store pointers to the class when copying is undesirable. The snippet below shows a practical pattern that avoids unnecessary copies by keeping heap-allocated objects in the queue via std::unique_ptr. #include <queue> #include <memory> #include <string> #include <iostream> class ProcessInfo { public: ProcessInfo(int pid, std::string filename, int memstart, char rw, std::string length) : pid_(pid), filename_(std::move(filename)), memstart_(memstart), rw_(rw), length_(std::move(length)) {} int pid() const { return pid_; } const std::string& filename() const { return filename_; } private: int pid_; std::string filename_; int memstart_; char rw_; std::string length_; }; int main() { std::queue<std::unique_ptr<ProcessInfo>> q; q.push(std::make_unique<ProcessInfo>(42, "data.bin", 0x1000, 'r', "128KB")); std::unique_ptr<ProcessInfo> item = std::move(q.front()); q.pop(); std::cout << item->pid() << " " << item->filename() << '\n'; } Notes and practical tips: std::queue exposes only front / back / push / pop ; it does not return the popped value, so move from front() before calling pop() . Use std::unique_ptr when single ownership is needed; use std::shared_ptr for shared ownership or polymorphism. If iteration or indexed access is required, use std::deque (the default underlying container) or another container directly instead of std::queue . std::queue is not thread-safe; add synchronization or a concurrent queue implementation for multi-threaded producers/consumers. Implementing a custom queue is only warranted for special behavior (lock-free requirements, custom allocation, strict capacity/ring-buffer semantics); otherwise the STL containers suffice. This complements the earlier answers and shows a safe, modern way to enqueue class instances while avoiding heavy copies. Recommended Answers Use a struct and the C++ STL queue to hold those data structs — David W 131 Jump to Post Nice :) In C++, why not rather use C++ (safe) strings? // in C++ ... why not use (safe) C++ string ? #include <iostream> #include <string> #include <queue> struct Person { const std::string name; int age; Person( const std::string& n="", int a=0 ): name(n), age(a) {} friend … — David W 131 Jump to Post All 7 Replies David W 131 Practically a Posting Shark 12 Years Ago Use a struct and the C++ STL queue to hold those data structs 12 Years Ago Here you go: #include <iostream> #include <queue> struct Person { const char* name; int age; }; int main() { std::queue<Person> pq; pq.push( Person { "John", 20} ); pq.push( Person { "Alice", 10} ); Person popped = pq.front(); std::cout << "I am " << popped.name; return 0; } David W 131 Practically a Posting Shark 12 Years Ago Nice :) In C++, why not rather use C++ (safe) strings? // in C++ ... why not use (safe) C++ string ? #include <iostream> #include <string> #include <queue> struct Person { const std::string name; int age; Person( const std::string& n="", int a=0 ): name(n), age(a) {} friend std::ostream& operator << ( std::ostream& os, const Person& p ) { return os << p.name << ", age " << p.age; } } ; int main() { std::queue < Person > pq; pq.push( Person( "David", 66 ) ); pq.push( Person( "John", 20 ) ); Person front = pq.front(); std::cout << "I am " << front << std::endl; return 0; } 12 Years Ago Yeah, David is right - we (I) should use string. const char* is a addict from work tbh ;) 12 Years Ago Got it guys! Is there a way to do this with a class though rather than a struct? 12 Years Ago I want to create a queue that can insert information into this class. class Processes { public: void setPID (int a) { PID = a; } int retrievePID() { return PID; } void setFilename (string input) { Filename = input; } string retrieveFilename() { return Filename; } void setMemstart (int a) { Memstart = a; } int retrieveMemstart() { return Memstart; } void setRW (char a) { rw = a; } int retrieveRW() { return rw; } void setFilelength (string input) { Filelength = input; } string retrieveFilelength() { return Filelength; } private: int PID; string Filename; int Memstart; char rw; string Filelength; }; David W 131 Practically a Posting Shark 12 Years Ago How does the above question, relate to your original thead here: I want to create a queue that holds certain information. I want it to hold multiple peices of information like below. Name, Age, Race, Sex. How can i create a queue FIFO. that holds multiple pieces of information like this that i can access or add into? Are you asking about coding, bottom up, your own class Queue? If not, please start a new thread for a new topic. Edited 12 Years Ago by David W because: fixed typo Reply to this topic Be a part of the DaniWeb community We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.
Markdown
[Menu](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#dw-sidebar "Toggle Menu") Menu [DaniWeb](https://www.daniweb.com/) [Log In](https://www.daniweb.com/connect/profile/login) [Sign Up](https://www.daniweb.com/connect/profile/login/signup) - [Read](https://www.daniweb.com/articles/latest/recommended) - [Contribute](https://www.daniweb.com/community/contribute/2) - [Meet](https://www.daniweb.com/connect/) # Multiple data in a queue 1. [Forums](https://www.daniweb.com/forums) 2. [Programming](https://www.daniweb.com/programming/4) 3. [Software Development](https://www.daniweb.com/programming/software-development/2) 4. Discussion / Question [![Member Avatar for mystycs](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/922966/mystycs) [mystycs](https://www.daniweb.com/members/922966/mystycs) 0 Newbie Poster 12 Years Ago I want to create a queue that holds certain information. I want it to hold multiple peices of information like below. Name, Age, Race, Sex. How can i create a queue FIFO. that holds multiple pieces of information like this that i can access or add into? Thanks\! [c++](https://www.daniweb.com/tags/c%2B%2B) [queue](https://www.daniweb.com/tags/queue) 0 0 Reply with Quote Share - 3 Contributors - 7 Replies - 909 Views - 1 Day Discussion Span - Latest Post [12 Years Ago](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#post2073872) Latest Post by David W ## Dani AI Generated 4 Months Ago Replies from @DavidW and @panqnik correctly point to the core idea: group related fields into one item and enqueue that item. For a class-based approach, prefer a compact, value-semantic class (constructor + const accessors) or else store pointers to the class when copying is undesirable. The snippet below shows a practical pattern that avoids unnecessary copies by keeping heap-allocated objects in the queue via std::unique\_ptr. ``` #include <queue> #include <memory> #include <string> #include <iostream> class ProcessInfo { public: ProcessInfo(int pid, std::string filename, int memstart, char rw, std::string length) : pid_(pid), filename_(std::move(filename)), memstart_(memstart), rw_(rw), length_(std::move(length)) {} int pid() const { return pid_; } const std::string& filename() const { return filename_; } private: int pid_; std::string filename_; int memstart_; char rw_; std::string length_; }; int main() { std::queue<std::unique_ptr<ProcessInfo>> q; q.push(std::make_unique<ProcessInfo>(42, "data.bin", 0x1000, 'r', "128KB")); std::unique_ptr<ProcessInfo> item = std::move(q.front()); q.pop(); std::cout << item->pid() << " " << item->filename() << '\n'; } ``` Notes and practical tips: - `std::queue` exposes only `front`/`back`/`push`/`pop`; it does not return the popped value, so move from `front()` before calling `pop()`. - Use `std::unique_ptr` when single ownership is needed; use `std::shared_ptr` for shared ownership or polymorphism. - If iteration or indexed access is required, use `std::deque` (the default underlying container) or another container directly instead of `std::queue`. - `std::queue` is not thread-safe; add synchronization or a concurrent queue implementation for multi-threaded producers/consumers. - Implementing a custom queue is only warranted for special behavior (lock-free requirements, custom allocation, strict capacity/ring-buffer semantics); otherwise the STL containers suffice. This complements the earlier answers and shows a safe, modern way to enqueue class instances while avoiding heavy copies. ## Recommended Answers Collapse Answers > Use a struct and the C++ STL queue to hold those data structs > > — [David W](https://www.daniweb.com/members/1080783/david-w) 131 [Jump to Post](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#post2073536) > Nice :) > > In C++, why not rather use C++ (safe) strings? > ``` > // in C++ ... why not use (safe) C++ string ? #include <iostream> #include <string> #include <queue> struct Person { const std::string name; int age; Person( const std::string& n="", int a=0 ): name(n), age(a) {} friend … > ``` > > — [David W](https://www.daniweb.com/members/1080783/david-w) 131 [Jump to Post](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#post2073718) ## All 7 Replies [![Member Avatar for David W](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1080783/david-w) [David W](https://www.daniweb.com/members/1080783/david-w) 131 Practically a Posting Shark 12 Years Ago Use a struct and the C++ STL queue to hold those data structs 0 0 Reply with Quote Share [![Member Avatar for panqnik](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1102612/panqnik) [panqnik](https://www.daniweb.com/members/1102612/panqnik) 0 Newbie Poster 12 Years Ago Here you go: ``` #include <iostream> #include <queue> struct Person { const char* name; int age; }; int main() { std::queue<Person> pq; pq.push( Person { "John", 20} ); pq.push( Person { "Alice", 10} ); Person popped = pq.front(); std::cout << "I am " << popped.name; return 0; } ``` 1 0 Reply with Quote Share [![Member Avatar for David W](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1080783/david-w) [David W](https://www.daniweb.com/members/1080783/david-w) 131 Practically a Posting Shark 12 Years Ago Nice :) In C++, why not rather use C++ (safe) strings? ``` // in C++ ... why not use (safe) C++ string ? #include <iostream> #include <string> #include <queue> struct Person { const std::string name; int age; Person( const std::string& n="", int a=0 ): name(n), age(a) {} friend std::ostream& operator << ( std::ostream& os, const Person& p ) { return os << p.name << ", age " << p.age; } } ; int main() { std::queue < Person > pq; pq.push( Person( "David", 66 ) ); pq.push( Person( "John", 20 ) ); Person front = pq.front(); std::cout << "I am " << front << std::endl; return 0; } ``` 1 0 Reply with Quote Share [![Member Avatar for panqnik](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1102612/panqnik) [panqnik](https://www.daniweb.com/members/1102612/panqnik) 0 Newbie Poster 12 Years Ago Yeah, David is right - we (I) should use string. const char\* is a addict from work tbh ;) 0 0 Reply with Quote Share [![Member Avatar for mystycs](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/922966/mystycs) [mystycs](https://www.daniweb.com/members/922966/mystycs) 0 Newbie Poster 12 Years Ago Got it guys! Is there a way to do this with a class though rather than a struct? 0 0 Reply with Quote Share [![Member Avatar for mystycs](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/922966/mystycs) [mystycs](https://www.daniweb.com/members/922966/mystycs) 0 Newbie Poster 12 Years Ago I want to create a queue that can insert information into this class. ``` class Processes { public: void setPID (int a) { PID = a; } int retrievePID() { return PID; } void setFilename (string input) { Filename = input; } string retrieveFilename() { return Filename; } void setMemstart (int a) { Memstart = a; } int retrieveMemstart() { return Memstart; } void setRW (char a) { rw = a; } int retrieveRW() { return rw; } void setFilelength (string input) { Filelength = input; } string retrieveFilelength() { return Filelength; } private: int PID; string Filename; int Memstart; char rw; string Filelength; }; ``` 0 0 Reply with Quote Share [![Member Avatar for David W](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1080783/david-w) [David W](https://www.daniweb.com/members/1080783/david-w) 131 Practically a Posting Shark 12 Years Ago How does the above question, relate to your original thead here: > I want to create a queue that holds certain information. > > I want it to hold multiple peices of information like below. > > Name, Age, Race, Sex. > > How can i create a queue FIFO. that holds multiple pieces of information like this that i can access or add into? Are you asking about coding, bottom up, your own class Queue? If not, please start a new thread for a new topic. 0 0 Reply with Quote Share Edited 12 Years Ago by David W because: *fixed typo* Share Facebook X LinkedIn [Reply to this topic](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#dw-reply-box) Be a part of the DaniWeb community We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge. [Sign Up — It's Free\!](https://www.daniweb.com/connect/profile/login/signup) Recommended Topics - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=3%2Fmember926132.jpg) Data Structures - Airport exercise 2](https://www.daniweb.com/programming/software-development/threads/443262/data-structures-airport-exercise "Hello I ma trying to practice on Data structure using java. I solved a lot of problems but this one looks interesting but I need some help understanding what I really have to do ... > write a program that simulates the operation of a busy airport that has only ...") - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=3%2Fmember825126.JPG) Generic Resizing Circular Array . Do i need to implement iterable ? 8](https://www.daniweb.com/programming/software-development/threads/462737/generic-resizing-circular-array-do-i-need-to-implement-iterable "Since the underlying data-structure used here is an array , which is itself iterable via `for-each()` , i'm wondering how much benefit implementing `Iterable` will provide here. I would appreciate if someone could review my code and suggest any further improvements. **Code:** import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; class ResizingCircularArray<E> ...") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) error 2065 2](https://www.daniweb.com/programming/software-development/threads/474146/error-2065 "Hi guys im a beginner at programming i started a book for beginners im only on lopps now but as uasuall i googled and wondered off into classes i keep getting this error, i initialized the float variables in the class by using the constructor. I'm not sure if this ...") - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=4%2Fmember1089735.jpg) multiple definition of 'main' in c 3](https://www.daniweb.com/programming/software-development/threads/487307/multiple-definition-of-main-in-c "hello friends i finally started programmation at school, we use ubuntu, at home i installed eclipse with MinGW i tried simple helllo world and it works but when i start mutiple exercices under same same project i get a compiler errormultiple definition of 'main' in c i tried `int main ...") - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=4%2Fmember1100807.jpg) class template problem 2](https://www.daniweb.com/programming/software-development/threads/473449/class-template-problem "I need a help in coding this program... write a C++ program to read a set of n numbers where n is defined by the user and print the contents of array in the reverse order using class template, numbers should include int and double data types... please reply soon....") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) Reading data from text file - C++ 4](https://www.daniweb.com/programming/software-development/threads/241957/reading-data-from-text-file-c "Hi, could anybody please tell me what i am doing wrong in this program. The goal is to read the student name and grade from a text file and print it on the screen. This is what i have so far. by the way this is for a school project ...") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) Building a database application 6](https://www.daniweb.com/programming/software-development/threads/19363/building-a-database-application "Hello everyone! I am planning to build a database application for my school to maintain school lockers. However, I have a few questions regarding that application: [list=1] [*]Is it possible to use access databse with C++? [*]Is there anyway to authenicate a user with C++? [*]How shoud I go about ...") - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=4%2Fmember1084710.jpg) C++ Object Oriented Queue(using double linked list) 2](https://www.daniweb.com/programming/software-development/threads/459537/c-object-oriented-queue-using-double-linked-list " //Author: Frank R. Mendez //Title: Object Oriented Queue //Description: This is program uses double linked list to store data in the queue its functions are enqueu,dequeue and display queue. //Hope it can help you in you future projects. Good vibes to all programmers! #include <iostream> using namespace std; struct Node ...") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) HELp Required.... 4](https://www.daniweb.com/programming/software-development/threads/114332/help-required "hi every body.... i need little help regarding project which we have to made in C++..... can someone guide me tht which type of topices can selected...... i am very much confused....:S") - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=fb%2F100001185643990.jpg) C Program - to accept 'n' strings from user and store it in a char array 10](https://www.daniweb.com/programming/software-development/threads/477820/c-program-to-accept-n-strings-from-user-and-store-it-in-a-char-array "C Program - to accept 'n' strings from user and store it in a char array I am currently using Turbo C++ Version 3.0 (one with blue screen) Can any one help with the C Code of the subject ?") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) need help 3](https://www.daniweb.com/programming/software-development/threads/209298/need-help "can anyone tell me how to write a programme to print numbers in following fashion 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1") - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=fb%2F100001791350421.jpg) C++ program to find sum of marks entered by 30 students 2](https://www.daniweb.com/programming/software-development/threads/467353/c-program-to-find-sum-of-marks-entered-by-30-students "C++ program to find sum of marks entered by 30 students using for loop or while loop/") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) Segmentation fault when reading from file 2](https://www.daniweb.com/programming/software-development/threads/304263/segmentation-fault-when-reading-from-file "The aim of the program is to read contents from 2 files and store it in struct variables.(This is actually a part of another program which stimulates pass2 of two pass assembler) [B]This code works fine.[/B] [code=c] #include<stdio.h> #include<stdlib.h> #include<string.h> struct optbl { char opco[10]; int value; }o_tbl[100]; struct symtbl ...") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) C Programming Priority queue questions 3](https://www.daniweb.com/programming/software-development/threads/486303/c-programming-priority-queue-questions "I was reading this example of Priority queues and have several questions. http://matrixsust.blogspot.com/2011/11/basic-priority-queue-in-c.html #include<stdio.h> #include<malloc.h> void insert(); void del(); void display(); //How exactly do structs in structs work? Do you need to do anything special with them? Is this a //form of a linked list? Which part of this is ...") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) Constructor nullpointerexception 14](https://www.daniweb.com/programming/software-development/threads/399225/constructor-nullpointerexception "Even after I set a for loop in my constructor I receive a null pointer exception any ideas why? here is a bit of the code [CODE] private String[] ingredientName,units = new String [40]; private double[] ingredientAmount = new double [40]; public Recipe() // Recipe Constructor example { for(int setVals ...") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) queue implimentation 9](https://www.daniweb.com/programming/software-development/threads/477174/queue-implimentation "please give me a code of multiple linked queue in data structure using c++") - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=fb%2F100007016557340.jpg) conditional if statements 3](https://www.daniweb.com/programming/software-development/threads/474864/conditional-if-statements "Write a program to get 3 numbers from user for integer variable a, b,and c. if a is not zero, find out whether it is the common divisor of b and c.") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) DATA STRUCTURES IN C++ 6](https://www.daniweb.com/programming/software-development/threads/455407/data-structures-in-c "I'm a little confused with an assignment here and i just needed someone to point me in the right direction. Design an inventory class that stores the following members: serialNum : An integer that holds a part’s serial number. manufactDate : A member that holds the date the part was ...") - [![Member Avatar](https://static.daniweb.com/connect/images/anonymous_small.webp) C++ Coding Question 6](https://www.daniweb.com/programming/software-development/threads/455977/c-coding-question "Im having a problem with the following exercise. I have the whole program working, however, the transaction time is not passing to the customer. The only element that this affects is the time that the customer leaves. Anny assistance would be greatly appreciated. Best, Dani Below are the 5 files ...") - [![Member Avatar](https://www.daniweb.com/images/resize/avatars?filename=fb%2F100000055435151.jpg) Queue problem using a function append. 2](https://www.daniweb.com/programming/software-development/threads/477948/queue-problem-using-a-function-append "Question:write a function append that takes as input two queues Q1 and Q2, appends the content of Q2 to Q1 and returns Q1. The protoype of the function is: queue<float> append(queue<float> Q1, queue<float> Q2); My problem here im completly stuck i do not understand how to work it. here are ...") Not what you need? Reach out to all the awesome people in our software development community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions. [Start New Topic](https://www.daniweb.com/community/contribute/2) [Topics Feed](https://www.daniweb.com/rss/2) [Reply to this Topic](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#dw-reply-box) ### ### Share Post Permanent Link Facebook Facebook X X LinkedIn LinkedIn ### Insert Code Block - Forums - [Forum Index](https://www.daniweb.com/forums) - [Hardware & Software](https://www.daniweb.com/hardware-and-software/1) - [Programming](https://www.daniweb.com/programming/4) - [Digital Media](https://www.daniweb.com/digital-media/5) - [Community Center](https://www.daniweb.com/community-center/3) - Recent - [Recommended Topics](https://www.daniweb.com/articles/latest/recommended) - [Newest Topics](https://www.daniweb.com/articles/latest?sort=started) - [Latest Topics](https://www.daniweb.com/articles/latest?sort=latest) - [Latest Posts](https://www.daniweb.com/posts/index/0) - [Latest Comments](https://www.daniweb.com/stats/comments/0) - [Top Tags](https://www.daniweb.com/community/tags/0/articles) - Tools - [Writing](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#dw-sb-writing) - [Start New Topic](https://www.daniweb.com/community/contribute) - [Markdown Syntax](https://www.daniweb.com/welcome/syntax) - [Newsletter Archive](https://www.daniweb.com/email/archive) - [Social](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#dw-sb-social) - [Top Members](https://www.daniweb.com/stats/toplist) - [Meet People](https://www.daniweb.com/connect/) - [APIs](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#dw-sb-apis) - [Connect API](https://www.daniweb.com/connect/developers) - [Forum API Docs](https://www.daniweb.com/welcome/api) - [Topics Feed](https://www.daniweb.com/rss) - Resources - [Community Rules](https://www.daniweb.com/welcome/rules) - [DaniWeb Premium](https://www.daniweb.com/donate/index) - [FAQ](https://www.daniweb.com/welcome/faq) - [About Us](https://www.daniweb.com/welcome/about) - [Advertise](https://www.daniweb.com/welcome/advertising) - [Contact Us](https://www.daniweb.com/welcome/contact) - Legal - [Terms of Service](https://www.daniweb.com/connect/welcome/tos) - [Privacy Policy](https://www.daniweb.com/connect/welcome/privacy) ![Opt-Out Icon](https://static.daniweb.com/privacyoptions.png) Your Privacy Choices © 2026 DaniWeb® LLC © 2026 DaniWeb® LLC - [FAQ](https://www.daniweb.com/welcome/faq) - [About Us](https://www.daniweb.com/welcome/about) - [Advertise](https://www.daniweb.com/welcome/advertising) - [Contact Us](https://www.daniweb.com/welcome/contact) - [Terms of Service](https://www.daniweb.com/connect/welcome/tos) - [Privacy Policy](https://www.daniweb.com/connect/welcome/privacy) ![Opt-Out Icon](https://static.daniweb.com/privacyoptions.png) Your Privacy Choices
Readable Markdown
[![Member Avatar for mystycs](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/922966/mystycs) 12 Years Ago I want to create a queue that holds certain information. I want it to hold multiple peices of information like below. Name, Age, Race, Sex. How can i create a queue FIFO. that holds multiple pieces of information like this that i can access or add into? Thanks\! ## Dani AI Generated 4 Months Ago Replies from and correctly point to the core idea: group related fields into one item and enqueue that item. For a class-based approach, prefer a compact, value-semantic class (constructor + const accessors) or else store pointers to the class when copying is undesirable. The snippet below shows a practical pattern that avoids unnecessary copies by keeping heap-allocated objects in the queue via std::unique\_ptr. ``` #include <queue> #include <memory> #include <string> #include <iostream> class ProcessInfo { public: ProcessInfo(int pid, std::string filename, int memstart, char rw, std::string length) : pid_(pid), filename_(std::move(filename)), memstart_(memstart), rw_(rw), length_(std::move(length)) {} int pid() const { return pid_; } const std::string& filename() const { return filename_; } private: int pid_; std::string filename_; int memstart_; char rw_; std::string length_; }; int main() { std::queue<std::unique_ptr<ProcessInfo>> q; q.push(std::make_unique<ProcessInfo>(42, "data.bin", 0x1000, 'r', "128KB")); std::unique_ptr<ProcessInfo> item = std::move(q.front()); q.pop(); std::cout << item->pid() << " " << item->filename() << '\n'; } ``` Notes and practical tips: - `std::queue` exposes only `front`/`back`/`push`/`pop`; it does not return the popped value, so move from `front()` before calling `pop()`. - Use `std::unique_ptr` when single ownership is needed; use `std::shared_ptr` for shared ownership or polymorphism. - If iteration or indexed access is required, use `std::deque` (the default underlying container) or another container directly instead of `std::queue`. - `std::queue` is not thread-safe; add synchronization or a concurrent queue implementation for multi-threaded producers/consumers. - Implementing a custom queue is only warranted for special behavior (lock-free requirements, custom allocation, strict capacity/ring-buffer semantics); otherwise the STL containers suffice. This complements the earlier answers and shows a safe, modern way to enqueue class instances while avoiding heavy copies. ## Recommended Answers > Use a struct and the C++ STL queue to hold those data structs > > — [David W](https://www.daniweb.com/members/1080783/david-w) 131 [Jump to Post](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#post2073536) > Nice :) > > In C++, why not rather use C++ (safe) strings? > ``` > // in C++ ... why not use (safe) C++ string ? #include <iostream> #include <string> #include <queue> struct Person { const std::string name; int age; Person( const std::string& n="", int a=0 ): name(n), age(a) {} friend … > ``` > > — [David W](https://www.daniweb.com/members/1080783/david-w) 131 [Jump to Post](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#post2073718) ## All 7 Replies [![Member Avatar for David W](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1080783/david-w) [David W](https://www.daniweb.com/members/1080783/david-w) 131 Practically a Posting Shark 12 Years Ago Use a struct and the C++ STL queue to hold those data structs [![Member Avatar for panqnik](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1102612/panqnik) 12 Years Ago Here you go: ``` #include <iostream> #include <queue> struct Person { const char* name; int age; }; int main() { std::queue<Person> pq; pq.push( Person { "John", 20} ); pq.push( Person { "Alice", 10} ); Person popped = pq.front(); std::cout << "I am " << popped.name; return 0; } ``` [![Member Avatar for David W](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1080783/david-w) [David W](https://www.daniweb.com/members/1080783/david-w) 131 Practically a Posting Shark 12 Years Ago Nice :) In C++, why not rather use C++ (safe) strings? ``` // in C++ ... why not use (safe) C++ string ? #include <iostream> #include <string> #include <queue> struct Person { const std::string name; int age; Person( const std::string& n="", int a=0 ): name(n), age(a) {} friend std::ostream& operator << ( std::ostream& os, const Person& p ) { return os << p.name << ", age " << p.age; } } ; int main() { std::queue < Person > pq; pq.push( Person( "David", 66 ) ); pq.push( Person( "John", 20 ) ); Person front = pq.front(); std::cout << "I am " << front << std::endl; return 0; } ``` [![Member Avatar for panqnik](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1102612/panqnik) 12 Years Ago Yeah, David is right - we (I) should use string. const char\* is a addict from work tbh ;) [![Member Avatar for mystycs](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/922966/mystycs) 12 Years Ago Got it guys! Is there a way to do this with a class though rather than a struct? [![Member Avatar for mystycs](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/922966/mystycs) 12 Years Ago I want to create a queue that can insert information into this class. ``` class Processes { public: void setPID (int a) { PID = a; } int retrievePID() { return PID; } void setFilename (string input) { Filename = input; } string retrieveFilename() { return Filename; } void setMemstart (int a) { Memstart = a; } int retrieveMemstart() { return Memstart; } void setRW (char a) { rw = a; } int retrieveRW() { return rw; } void setFilelength (string input) { Filelength = input; } string retrieveFilelength() { return Filelength; } private: int PID; string Filename; int Memstart; char rw; string Filelength; }; ``` [![Member Avatar for David W](https://static.daniweb.com/connect/images/anonymous.webp)](https://www.daniweb.com/members/1080783/david-w) [David W](https://www.daniweb.com/members/1080783/david-w) 131 Practically a Posting Shark 12 Years Ago How does the above question, relate to your original thead here: > I want to create a queue that holds certain information. > > I want it to hold multiple peices of information like below. > > Name, Age, Race, Sex. > > How can i create a queue FIFO. that holds multiple pieces of information like this that i can access or add into? Are you asking about coding, bottom up, your own class Queue? If not, please start a new thread for a new topic. Edited 12 Years Ago by David W because: *fixed typo* [Reply to this topic](https://www.daniweb.com/programming/software-development/threads/474865/multiple-data-in-a-queue#dw-reply-box) Be a part of the DaniWeb community We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.
Shard168 (laksa)
Root Hash18142197517966842768
Unparsed URLcom,daniweb!www,/programming/software-development/threads/474865/multiple-data-in-a-queue s443