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);

}

Recommended Answers

All 2 Replies

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

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.