« first day (1462 days earlier)      last day (1374 days later) » 

5:13 AM
hey guys. suppose I have a class that extends std::enable_shared_from_this<>. is there some workaround to use shared_from_this() within this class constructor?
 
6:05 AM
Hello I have a vector and I need to iterate through a for loop extracting certain sections of the vector each time. is the best strategy here to move the exact section into another container and then perform some other comparison tasks ?
each time i run the for loop i need to extract a small segment of the original vector and then proceed to use that small segment.
would std::move range be the best option there ?
the moved segment has only local scope
each time the loop runs i get a new section
 
 
7 hours later…
user13168561
12:47 PM
Heyyy
 
user13168561
```#include <iostream>
using namespace std;

my_funct(string value)
{
string arr[] = {value};
cout << arr;
}

main()
{
string names;
while true
{
names = cout << "Enter your name: \n";
if (names != '0')
{
break;
}
getline(cin, names);
my_funct(names);
}
}```
 
user13168561
I'm stuck here :(
 
user13168561
I'm new to C++ (came from python) and getting these basic errors about datatypes... Don't know how to solve
 
4 messages moved from Lounge<C++>
@Roxanne You have my condolences, C++ is going to be a very very cruel world for you
what's the confusion?
 
user13168561
Haha, yeah
 
user13168561
12:55 PM
I know
 
user13168561
Umm... did you tried the code?
 
user13168561
Can you correct it and let me know where I'm wrong?
 
user13168561
And if corrected can you give this kid some advice 'bout C++?
 
user13168561
I really need it...
 
well... string[] doesn't do what you think it does... C++ doesn't have built in automatic sized arrays like python. That's a C style array which needs to have dimensions set at compile time. A better choice is std::vector<std::string> which is closer to what you're used to
while true isn't a thing in C++, the while statement needs a parenthesized statement after it to indicate the loop condition so it has to be while (true)
 
user13168561
1:03 PM
Oh, Didn't know that! Thnx just checking the links...
 
user13168561
How much time were you on C++
 
I've been doing C++ since highschool back around 2000
relearned it from scratch to unlearn bad habits in 2013ish
 
user13168561
You're a Pro
 
user13168561
Salute to you!
 
For what it's worth the reference site we use around here is Cppreference we prefer it over the alternatives because the others have been either flat out wrong, give horrible examples, or are way out of date.
I'd highly recommend book marking it
 
user13168561
1:08 PM
Sure I did!
 
user13168561
I wish if it has a good UI too...
 
we also tend to avoid using namespace std because as the core stdlib that can cause conflicts with other libraries
 
user13168561
So std::cout?
 
it's easier to just type the std:: in front of stdlib functionalities
yes, that said... uni's sometimes require it for dumb reasons
 
user13168561
XD
 
1:10 PM
On the topic of C style arrays... en.cppreference.com/w/cpp/language/array
you should read that
if you need a fixed length array in C++ we recommend using std::array
 
user13168561
Hey, can you fix my code? I don't know after doing changes also giving me errors ://
 
@Roxanne so you'll need to include the headers for what you're using... if you're using strings you need to #include <string>
main needs a return type... the standard requires that to be int
so names != '0' doesn't make sense
the result of operator << on std::ostream is not assignable to std::string
 
user13168561
Oh so i should be doing just court, not names = cout?
 
std::cout << "Enter your name: \n";
is fine
but it's a std::ostream which means it's output only
so you can't input from cout
 
user13168561
Umm... so how could I check if user types 'quit' then the program must end?
 
1:21 PM
if(!std::getline(cin, val)){
    break;
}
if(val == "quit"){
    break;
}
So this is a compile fixed version: godbolt.org/z/WWjMWM
but note that it isn't a working version
just because it compiles doesn't mean you should use that code
 
user13168561
So what should I do?
 
1:36 PM
understand what you want to do first, write that out in plain statement (not code)
then figure out the best way to do it
The search function on cppref is your friend
it's pretty good
so for example I'd suggest looking into function syntax in C++ en.cppreference.com/w/cpp/language/functions
I assume this is for Uni work?
 
user13168561
U mean University?
 
yes
 
user13168561
I'm in school only...
 
ah, so one of the best ways to get ahead in programming is to be good at picking up languages
 
user13168561
I picked up C++ for CP
 
1:43 PM
CP?
 
user13168561
Competetive programming...
 
ah, good luck
 
user13168561
Python is seducing me to use libraries
 
user13168561
That's why
 
C++ has plenty of libraries too
but yeah I can see why
 
user13168561
1:46 PM
I believe in doing projects... Not CP. I was building an application for B2B users that they can scrape any website with just point and click interaction and it's 100% working! I used Python + QT for it... But my PC is 10 years old so my GUI app is looking messed up ://
 
user13168561
So I'm waiting for my MacBook Pro next year, and until then, I'm learning C++ and doing competitive programming
 
Ah ok, C++ isn't bad to learn. You'll learn a lot about hardware, the ugly side of computing, and nasal demons
 
user13168561
XD
 
user13168561
Yeah.
 
user13168561
And QT is for C++ too
 
user13168561
1:49 PM
So hey just another question...
 
user13168561
Is it possible to connect my python code with C++?
 
Yes in both directions. Either you can have C++ code 'host' python. Or you can have python use C++ plugins
 
user13168561
Like I take input from C++ and pass that input to python so as to perform different tasks on it...
 
user13168561
Really? That's great!
 
user13168561
How could I do that?
 
1:50 PM
Yes you see it in scripting for large applications.
 
user13168561
Thanks!
 
user13168561
Are you a software engineer?
 
Yes
 
user13168561
Wow! In which company?
 
I'd rather not say
 
user13168561
1:55 PM
Ok. I got it. NP
 
user13168561
Heyyy listen listennn listenn listenn
 
user13168561
That code is producing some noise?
 
user13168561
I changed std::cout << arr[0]; to std::cout << arr[1];
 
user13168561
And when I input "ab" then it's producing a very loud beeping noise
 
user13168561
In an infinite loop!!!
 
user13168561
1:58 PM
Even after closing my VSCode!
 
user13168561
I've to restart my PC to get rid of it ://
 
@Roxanne so remember when I said this was a bad idea to run this code?
std::string arr[] = {value};
std::cout << arr;
is an extraordinarily bad idea
 
user13168561
Why?
 
user13168561
And what should I do?
 
what do you think std::cout << arr; does?
 
user13168561
2:04 PM
prints the whole array, i guess?
 
Nope! C++ doesn't have facilities to do that
you have to use a loop
 
user13168561
My Bad.
 
user13168561
But can you tell me why it was behaving like that?
 
nasal demons
 
user13168561
So it doesn't have any reason for doing so?
 
2:07 PM
well if the code has undefined behavior... and it does then yes it has a reason
std::string arr[] = {value}; is not legal because it has no length
 
user13168561
Why C++ didn't give me any errors or warnings then?
 
it might compile... it might not
@Roxanne it's not required to?
 
user13168561
Hmm... so what I need to do is to take care of data types and define everything properly?
 
Yes, it's possible that the compiler is seeing that as legal for a length of 1
but regardless beware of undefined behavior. The compiler is not required to warn about it
 
user13168561
Oh, okay. I got you!
 
user13168561
2:11 PM
Need to be more careful with C++
 
3:22 PM
Hi everyone, I've been reading a tour of c++ and I'm on chapter 4 (classes) and I have a question wrt member variables and their initialization in the initializer list of a constructor. https://pastebin.com/susx3rqN

Inside my Vector_container class that is a subclass of my abstract class Container, I use my Vector class object v, like so 'private: Vector v' and then in the constructor ': v(n)', how does this work? Because in main I obviously can't do 'Vector v', followed by 'v(n)' on the next line. It seems inconsistent. Should I just accept that this is how the syntax is? I hope you guys
 
 
8 hours later…
11:34 PM
Anyone? :(
 

« first day (1462 days earlier)      last day (1374 days later) »