Their must be a more efficient way of doing this.

I'm planning on building an auto trading algorithm, but I'm currently not sure what the best way is to have arrays of a size of roughly 50 continually updating of chart data from specific stocks. That is not the problem, I want to easily be able to put commands in the console like "add GOOG", "add BABA", and "remove FB"?

What I want to happen:
"add BABA" - adds an array of size 50 to the program, with the name of BABA.
"remove GOOG" - removes the array GOOG


Problem 2:
Without having 10-20 loops going is their a way to update 10 or more arrays every second at the same time, without using a loop, and still have the functionality of arrays being able to be added and removed?

Ask any questions you may need to be able to answer these questions.
Note: Not on a PC right now, but on a tablet therefor cannot test code.

I think you should use vectors.
You could make a map of arrays or vectors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <sstream>
#include <string>

#include <map>
#include <vector>

int main()
{
    std::map<std::string, std::vector<int> > stocks;
    
    std::string line;
    std::getline(std::cin, line);
    while(line != "quit") {
        
        std::stringstream ss(line);
        
        std::string command;
        std::string item_name;
        
        ss >> command >> item_name;
        
        if(command == "add")
            stocks[item_name] = std::vector<int>(50); // add vector with 50 elements
        else if(command == "remove")
            stocks.erase(item_name); // remove item

        // print contents
        for(std::map<std::string, std::vector<int>>::iterator pair = stocks.begin(); pair != stocks.end(); ++pair)
            std::cout << pair->first << std::endl;
        
        std::getline(std::cin, line);
    }

    return 0;
}


What do you mean with problem 2?
Last edited on
Topic archived. No new replies allowed.