0

I am running this loop where I am substr a vector like below and then ´creating´ a new string "NewData" that I will pushback in a new vector.
The thing is that I got an Error message when running this code but if I instead change these 3 lines to this, then it will work:

One = ReadInData;
Two = ReadInData;
Three = ReadInData;

I cant understand why it works when I take the .substr away. The entire strings from the beginning are about 40 characters so the characters that I am trying to substr do exist ?

std::vector<string> ReadInDataCorrectDates;
std::string One, Two, Three;
std::string NewData;
			 
for (int i = 0; i < countLines; i++)
{
					
	One = ReadInData[i].substr(0, 2);
	Two = ReadInData[i].substr(3,2);
	Three = ReadInData[i].substr(6,4);

	NewData = Three + Two + One + ReadInData[i];

	ReadInDataCorrectDates.push_back(NewData);

}
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Jennifer84
0

I managed to find out the problem. I was reading in an emty space with File1.get() so the element number 5 below was emty. So I did make it work now to be sure that (string != "") is push_back into the vector.
So now it works.
Thank you...

for (int i = 0; i < 10; i++)
{
					
	One = ReadInData[i].substr(0, 2);

I see no error. What exactly does the error message say?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.