« first day (1042 days earlier)      last day (1802 days later) » 

nwp
9:13 AM
@JonasStein To me it doesn't look unclear, it looks like an xy problem with a bit of too-broad. The answer, as pointed out in the comments, is probably that you should not have a test based on files. And the part "How do I make the test not rely on files" is too broad. There can't be an expert answer for that.
There should be a way to pass a std::ostringstream instead of a std::ofstream at the right spot in your code and then the framework should handle the test reasonably well. The program to compare files is just a hack to work around the problem.
If you want to stick to the file strategy, which is not completely unreasonable, you can use diff to compare files. You can probably get that on Windows too.
But integrating external programs into a unit test will probably be a bit of a pain.
 
 
11 hours later…
7:57 PM
vector<int>::const_iterator vs;
vs = nums.begin();
vector<int> vec;
vec.push_back(*(nums.end() - 1));
nums.pop_back();
while (!nums.empty())
{
    cout << *vs++;
    vec.push_back(*(nums.end() - 1));
    nums.pop_back();
}
 
nwp
8:13 PM
@Rick The code is not correct. And it can be made a bit simple.
 
@nwp what would it look like
 
nwp
Oh wait, it's actually not incorrect.
*(nums.end() - 1) can be written as nums.back().
vs should really use auto.
Maybe the example is too simple, but you could print the elements and then just move the vector.
Maybe you want to use std::back_inserter.
 
really i'm just doing something in a roundabout way. what I really want to do is walk the iterator as I add items to it
 
nwp
That sounds like you want std::back_inserter.
 
can you show me what that would look like?
 
nwp
8:18 PM
Hmm, the example is not particularly good.
 
like I really just want to do for(auto val: vec){ vec.push_back(nums.pop_back() )}
 
nwp
Does it have to be one element at a time?
Can you not use nums.insert(std::begin(vec), std::end(vec));?
 
Well the idea is that you decide how those elements get pushed in so doing it all at once would make it sort of pointless
 
1 message moved from Lounge<C++>
 
@Puppy thanks :)
@nwp Unfortunately, that example is not what I'm looking for. imagine vec only having one element. I walk that first element, in the loop I push another element then the iterators goes to the element I just pushed in and so on, untill the iterator has no more elements.
to that*
 
nwp
8:30 PM
What is the problem you actually want to solve?
 
@nwp I just want to write shorter code, this is more of style type of thing.
 
nwp
It's difficult to suggest shorter code when I don't know the problem.
 
@nwp do what I did but shorter and more elegantly preferably using a vector
 
nwp
That sounds like an xy-problem.
 
@nwp I don't have a problem, I can do this a million different ways. I just want to know if it can be done shorter and more idiomatically with a vector.
 
nwp
8:41 PM
Then you need to make a better example since I suggested an easier way to do what you did in the example and it didn't solve your original problem.
 
@nwp ok I'll get you a better example
 
9:10 PM
@nwp I figured it out. turns out it's just as ugly with an iterator.
I feel vectors make you lazy in like a stupid way (this is just my personal opinion);
 

« first day (1042 days earlier)      last day (1802 days later) »