« first day (1570 days earlier)      last day (1507 days later) » 

10:09
what is the best way to split a c++ string by whitespace these days?
is there no method like split(word, " ") like in python?
10:43
i am trying to write a function to sort royal names but this just wont compile
warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
for (int i = 0; i < res.size(); i++) {
i cannot see what the issue is
It is a warning for type mismatch.
res.size() returning a "size_type" which corresponds to long unsigned int.
Ref: http://www.cplusplus.com/reference/vector/vector/size/

counter variable 'i' is a plain old int.
Hence the mismatch and the warning.
yes but it should names.size()
where names is a vector
11:05
its appears that the custom comparator is not working well
olution.cpp:25:10: note: candidate: ‘bool comp::operator()(std::__cxx11::string&, std::__cxx11::string&)’ <near match>
bool operator()(string &n1, string &n2) {
^~~~~~~~
have i written the custom comparator all wrong, like all the return statements are rubbish?
1) is the code 2) is the complilation errors
11:48
@Permian boost has a method
yeah i saw that since
what do you think of my code for it now see 2nd from last link?
are you sure you want my opinion? I'm nitpicky as hell
i cant get that code to compile at all
i need to be ruined
the immediate issues are

for (int i = 0; i < res.size(); i++) {
for (int i = 0; size_t{i} < res.size(); i++) {

and

bool operator()(string &n1, string &n2) {
bool operator()(const string &n1, const string &n2) {
12:07
ok ill start there @PeterT thanks
1) why does the comparator need const arguments?
the error tells you why. error: binding reference of type ‘std::__cxx11::string&’ {aka ‘std::__cxx11::basic_string<char>&’} to ‘const std::__cxx11::basic_string<char>’ discards qualifiers
"can't bind "string&" to a "const string", you you know whatever called the comparator tried to call it with a const value
but in general if you don't a mutable reference, don't require one
also watch your whitespace
ok thanks guy, im struggling with the solutions myself, so will need to do some googling
@PeterT yeah it looks like online custom comparators are always written with const arguments
@Mgetz that is like information overload
for (int i = 0; size_t{i} < res.size(); i++) {
i cant see how this is being generated, because res should be a vector<string> which has a size() function
12:27
right and the return type of size() is size_t which is unsigned
dpaste.org/5Ofb (latest code)
ah i must return an array from that function
weird
if you don't need i to be signed you can just start with
for (size_t i = 0; i < res.size(); i++) {
ive changed that, its just not happy with my custom comparator at all
12:47
@Permian you're trying to sort a const& vector
in-place sorting is a mutable operation
13:30
omg
that was such a simple fix
 
3 hours later…
16:34
my distance function wont work for my implementation of dijsktra algorithm
this is my dist vector 0, 51, 104, 154
which is clearly meaningless but I cant see why I am claculating this wrong. Is it something do to with the character codes?
my parent vector is working correctly
17:23
updated code
 
1 hour later…
18:50
Hi
hi
have you got any idea how to diagnose seg faults in c++?
debugger
then go step by step
do you know how to deal with time in c++?
probably the time module
i wouldnt take advice from im crap
I have a string containing a timestamp, say "2020-October-18 23:12:34"
@Washery basic time durations are in <chrono> , calendar stuff is not standardized yet I think, so you can use boost or whatever other library you want
18:52
I need to check if two weeks have passed
This is what I was doing
const auto now = std::chrono::system_clock::now();
const auto twoWeeks = std::chrono::hours(24 * 14);
const auto lastTwoWeeks = now - twoWeeks;
const auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(lastTwoWeeks.time_since_epoch()).count();
then somehow convert the time string and compare with "millis"
well there's nothing in the standard lib to do the conversion I think. Posix hast strptime or you can use boost::date_time to do the parsing
I successfully converted the string into a std::time_t var
 
1 hour later…
20:15
if (("A" <= result[0]) || (result[0] <= "Z") || ("A" <= result[1]) || (result[1] <= "Z")){
result[0] is a len 1 string
why am i not allowed to do the comparison? (it says because it char vs string)
it's "const char[2]" compared to a "std::string", there's just no comparison operator defined for those two
you can still manually use strncmp if you like
hmmm ok
@PeterT std::string is implicitly constructible from string literals. That should not be a problem. Example
thats what i thought
@Permian See the link in my previous comment. If result[0] is actually an std::string your comparison should work. If this is not the case, you need to provide a more detailed description of the problem.
20:24
Invalid operands to binary expression ('char' and '__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char> >::value_type' (aka 'std::__cxx11::basic_string<char>'))clang(typecheck_invalid_operands)
it says char, so you have 'A' instead of "A"?
its fixed! thanks
right
i need to create a graph using unordered_map<char, vector<pair<char,int>> > graph;, however my parsing creates strings not char, but when I use the graph i need to use chars because it is easier to convert theses to numbers (for an index). is there a way to convert length 1 strings to chars?
str[0]
that flags up an error , with graph[result[0]]
Seems like std::string does have comparison operators for string literals : en.cppreference.com/w/cpp/string/basic_string/operator_cmp.
20:32
andidate function not viable: no known conversion from '__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char> >::value_type'
@Permian to what?
an error
it say no valid conversion from std::string::value_type which is char
I was asking what the other half of that error is
im going to build the graph using strings
somehow I need to map "A" to 0, "B" to 1,....
lol, are you just not going to give me the full error message?
20:34
No viable overloaded operator[] for type 'unordered_map<char, vector<pair<char, int> > >'clang(ovl_no_viable_subscript)
unordered_map.h(973, 7): Candidate function not viable: no known conversion from '__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char> >::value_type' (aka 'std::__cxx11::basic_string<char>') to 'const std::unordered_map<char, std::vector<std::pair<char, int>, std::allocator<std::pair<char, int> > >, std::hash<char>, std::equal_to<char>, std::allocator<std::pair<const char, std::vector<std::pair<char, int>, std::alloc
ok, so result is a vector not a string?
i think i am going to build the grpah using strings for ease at this point
the value is vector<pair<char/string, int>>
Is your unordered map const?
Consider posting a question with a Minimal, Reproducible Example.
20:37
@FrançoisAndrieux key types of a map are always made const
i think i will come back to this
when i am writing the logic for dijstrka's with keys mapping to indices
21:15
if (unique_nodes[{result[0],result[1]}] == d || unique_nodes.find([result[0],result[1]]) == unique_nodes.end()) {
        graph[result[0]].push_back({result[1],d});
        graph[result[1]].push_back({result[0],d});
        unique_nodes[{result[0],result[1]}] = d;
} else {
      E2 = true;
                }
how would you query for a pair key in an unordermap<pair<string,string>,int>?
mine does not work and i cant find anyone online who has asked this before
auto p = make_pair(result[0],result[1]);
if (unique_nodes[p] == d || unique_nodes.find(p) == unique_nodes.end())
that didnt help either
unique_nodes[p] inserts a value for p, so the second condition is always false
how can it always be false? also its meant to find the element not insert it
21:32
std::map<int,int> m;
m.size(); //0
m[1];
m.size(); //1
absolutley no idea what you mean
haha
in "m[1]" if there's no entry in the map with the value "1" then a new element will be inserted
so doing m.find(1) will always be != m.end() after "m[1]"
my brain is blown
i think i need to sleep

« first day (1570 days earlier)      last day (1507 days later) »