c++ - Why Doesn't My String In My Vector Change Value? -
I am trying to change the value of time in my vector of structs. As a result, the value of shares should be produced as 1430 [1]. I think the time is different.
The share is the name of my vector, I've already weighed with the vectors for each structure. The stock is a straight, in which there is string time.
// It is in the Share.cpp vector & lt; Share & share; Unsigned conversion time = 1430; Std :: stringstream out; Outside & lt; & Lt; ConvTime; // Make a string stream share of the shares [1]. Time = out.st (); Std :: cout & lt; & Lt; Shares [1] .time; Struct share {// member structure std :: All information in the string date; Std :: string time; Double price; Double volume; Double value; Std :: string condition; // Not a nurse in this assignment}; But my shares [1] Time stays in its original value and not 1430. What was I doing wrong?
Before you actually use those items, you have to insert objects in the vector. When you write:
vector & lt; Share & gt; Shares; There is no item in it yet
share [1]. Time Due to undefined behavior. If you use [] instead of the .at () function, then you get an exception instead of exception behavior. To put objects in vector, either push_back () , or shares.resize (num_objects) .
Comments
Post a Comment