• We've upgraded our forums. Please post any issues/requests in this thread.

Vector of structs? C++

Joined
May 19, 2007
Messages
7,662 (1.99/day)
Likes
536
Location
c:\programs\kitteh.exe
Processor C2Q6600 @ 1.6 GHz
Motherboard Anus PQ5
Cooling ACFPro
Memory GEiL2 x 1 GB PC2 6400
Video Card(s) MSi 4830 (RIP)
Storage Seagate Barracuda 7200.10 320 GB Perpendicular Recording
Display(s) Dell 17'
Case El Cheepo
Audio Device(s) 7.1 Onboard
Power Supply Corsair TX750
Software MCE2K5
#1
Im writing a sort program with a vector i want to sort (which is to store some items which i counted previosly and the name its assigned to, search engine type thing)

Code:
struct filestore
{
    string filename;
    int wordcount;
}

vector <filestore> filesortlist;
my problem is how do i now assign something, i want to load in the details, to i create a temporary filestore struct to hold it then i pop back or is there something more elegant?

al
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
20,905 (6.25/day)
Likes
9,998
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#2
A vector of structs is no different from a vector of strings except in what each index of the vector contains (an instance of your struct instead of an instance of a string).
 
Joined
May 19, 2007
Messages
7,662 (1.99/day)
Likes
536
Location
c:\programs\kitteh.exe
Processor C2Q6600 @ 1.6 GHz
Motherboard Anus PQ5
Cooling ACFPro
Memory GEiL2 x 1 GB PC2 6400
Video Card(s) MSi 4830 (RIP)
Storage Seagate Barracuda 7200.10 320 GB Perpendicular Recording
Display(s) Dell 17'
Case El Cheepo
Audio Device(s) 7.1 Onboard
Power Supply Corsair TX750
Software MCE2K5
#3
what i was doing is storing list of file snad the amount of hits in them, ive been instructed to use a map ... now i need to read and get back to you guys if i dont understand
 
Joined
May 19, 2007
Messages
7,662 (1.99/day)
Likes
536
Location
c:\programs\kitteh.exe
Processor C2Q6600 @ 1.6 GHz
Motherboard Anus PQ5
Cooling ACFPro
Memory GEiL2 x 1 GB PC2 6400
Video Card(s) MSi 4830 (RIP)
Storage Seagate Barracuda 7200.10 320 GB Perpendicular Recording
Display(s) Dell 17'
Case El Cheepo
Audio Device(s) 7.1 Onboard
Power Supply Corsair TX750
Software MCE2K5
#4
navigating and sorting maps (c++)

i want to do the equivalent of this
Code:
int i,j;
    for(i=0;i<10;i++)
    {
        for(j=0;j<i;j++)
        {
            if(array[i]<array[j])
            {
                int temp=array[i]; //swap 
                array[i]=array[j];
                array[j]=temp;
            }

        }

    }
with maps

Code:
map <string, int> m1;
map <string, int>::iterator pos;

for(pos = m1.begin(); pos!= m1.end(); ++pos)
    {
        for(pos = m1.begin(); pos!= m1.end(); ++pos)
        {
             //lost?
    }

}
im sorting by the int
 
Last edited:
Joined
May 19, 2007
Messages
7,662 (1.99/day)
Likes
536
Location
c:\programs\kitteh.exe
Processor C2Q6600 @ 1.6 GHz
Motherboard Anus PQ5
Cooling ACFPro
Memory GEiL2 x 1 GB PC2 6400
Video Card(s) MSi 4830 (RIP)
Storage Seagate Barracuda 7200.10 320 GB Perpendicular Recording
Display(s) Dell 17'
Case El Cheepo
Audio Device(s) 7.1 Onboard
Power Supply Corsair TX750
Software MCE2K5
#5
anyone?