Hi All,
Well I've been stuck for a while here. I'm trying tp write a function called TransfertoSwingID which will transfer a line of data held in a struct contained in a vector to a new vector of structs.
Basically as I'm iterating through the vector of structs called "prices", if the conditions are true, then I need to transfer/copy the data held in the struct that is being pointed to by *(it-1).
There are 2 sets of conditions, if the 1st set is true, then I pass an integer, 0, to the function so that the data transferred would be identified as a "SL". If the 2nd set of conditions is true, then I pass int 1 so that the data transferred would be identified as "SH". The idea is then to print out the data which would look like this:
Date Time Open High Low Close Volume Identifier
(where the last string is the identifier, either SH or SL)
The original vector "prices" contains the first 7 variables above in the structs it contains.
Any help would be greatly appreciated. Thanks.
1. int main(int argc, char* argv[])
2. {
3.
4. if (argc != 2)
5. {
6.
7. std::cerr <<
8.
9. "Usage: " << argv[0] << " filename " << std::endl;
10.
11. return EXIT_FAILURE;
12. }
13.
14.
15. PriceList prices;
16.
17. ReadPricesFromFile(argv[1], prices);
18. if (prices.size() < 2)
19. std::cout << "Vector size less than 2!" << std::endl;
20. else
21. std::cout << "Vector has 2 or more elements" << std::endl;
22.
23.
24.
25. std::vector<PriceInfo>::iterator it;
26. it = prices.begin();
27. advance (it, 2);
28.
29.
30.
31. for (;it!= prices.end();)
32. {
33.
34. if // 1st condition
35.
36. {
37.
38. if // another condition
39.
40. TransferToSwingID(0, *(it-1)); //( *(it-1) is likely wrong syntax)
41.
42.
43. }
44.
45.
46. {
47. if // 1st condition for 2nd possibility
48.
49.
50. {
51. if // 2nd condition
52. TransferToSwingID(1, *(it-1));
// (how does one pass the contents pointed to by iterator it?)
53.
54. }
55. }
56.
57.
58. ++it;
59. }
60.
61. int TransferToSwingID (int type, struct PriceInfo&)
62.
63. {
64. struct SwingIdentified
65. {
66. double Id_Open;
67.
68. double Id_High;
69.
70. double Id_Low;
71.
72. double Id_Close;
73.
74. unsigned int Id_Volume;
75.
76. unsigned int Id_Time;
77. std::string Id_Date;
78.
79. std::string Identifier;
80. };
81.
82.
83. // some code here to transfer the contents of *(it-1)
84. // to a new vector of struct of type SwingIdentified
85.
86. if (int type=0)
87.
88. std::string Identifier = "SL";
89.
90. else if (int type=1)
91.
92. std::string Identifier = "SH";
93.
94.
95.
96.
97.
98. }
99.
100.
101.
102. char quitKey;
103.
104. std::cout << "Press q to quit" << std::endl;
105.
106. std::cin >> quitKey;
107.
108. return EXIT_SUCCESS;
109. }