« first day (2403 days earlier)      last day (450 days later) » 

Ron
12:15 PM
When reading from a file stream one line at the time, should we use the while(fs) { std::getline(fs,s);} or the while(std::getline(fs,s)) { // code} approach?
The first one seems to read an extra line. Duplicates the last line in the file if it has no eoln character in it.
 
nwp
The first one has the issue of first checking for errors and then doing the reading.
It doesn't read an extra line, it fails to read past the end and s may have some data left over from the previous line.
You should probably do something like
while(true) {
    if (!std::getline(fs,s)) {
        break;
    }
}
Though at that point may as well go for the second approach.
 
Ron
I see, thanks.
 
or you can go with the for loop: for(std::getline(fs,s);fs;std::getline(fs,s))
 
 
3 hours later…
3:19 PM
std::smatch m;
std::string::const_iterator pos;

std::regex_search(pos, end, m, rex, std::regex_constants::match_continuous))

pos = m[RAll].second;

what is this .second I don't understand. Rall is 0 so it's m[0] and that is a string, but where comes that .second .... Is a member of std::string?
 
Suppose to have a vector of chars:

std::vector<char> a = {'c', 'a', 'c', 'i', 'o', 'c', 'a', 'v', 'a', 'l',
'b', 'a', 'c', 'c', 'h', 'e', 't', 't', 'a', 'a',
'o', 's', 't', 'r', 'o', 'n', 'a', 'u', 't', 'a'};

Let's say that they represent string whose length is 10. I want to sort them in order to obtain the following result:
So the result should be:
std::vector<char> a = {'b', 'a', 'c', 'c', 'h', 'e', 't', 't', 'a', 'a',
'c', 'a', 'c', 'i', 'o', 'c', 'a', 'v', 'a', 'l',
'o', 's', 't', 'r', 'o', 'n', 'a', 'u', 't', 'a'};
 
3:32 PM
@CătălinaSîrbu it's a std::pair IIRC but in this case it's a std::sub_match
which inherits from pair oddly
 
can't believe i didn't see that .... thanks
 
yeah pos is the position after the match
tbf searching it gave weird results
I had to go in through regex_search to find that
 
and .matched comes from pair also ?
like m[0].matched
or is from sub_match
quote from submatch: This class adds to the data inherited by pair a public member variable of type bool, named matched.
 
no that comes from the specialization
 
4:08 PM
@reuseman The obvious choice would be to use an std::vector<std::string>, in which case sorting them becomes trivial.
If you can't use a vector<string>, the next most obvious choice would be to use std::string_views of the data. That supports a copy that will let you copy data from one place to another.
 
4:54 PM
@Mgetz But what that match does? compares who with who
 
not following
 
matched from std::smatch .matched
 
5:52 PM
@JerryCoffin Unfortunately I cannot use std::string. I need to work on the std::vector<char>
 
 
1 hour later…
6:53 PM
since what version you can write void f(int, int);
instead of void f(int a, int b)
 
nwp
7:11 PM
Since pre-standard C I think.
 

« first day (2403 days earlier)      last day (450 days later) »