Hussein
hi
I want to start learning c++, Does anyone have a roadmap?
start with a tutorial
or youtube videos then start a simple project you like to work on
C and C++ tutorial usually cover computer memory and some basic understanding of it
learning C first isn’t necesary, even though I’m good with C I still suffer a lot with C++ standard library and object oriented programming
the two languages are similar in syntax but wildly different in standard library which is the thing that provide the basic functions you will use by default in your code like (printf() or cout <<)
Hussein
For instance I'm not able to differentiate btw struct nd class??
a class can have functions while a struct can’t have functions by default.
a class can restrict the access of some elements with(protected or private)
also with classes the style of programming will be different (called object oriented programming btw)
also you are provided with constructors which are something that let you run a function once an object (something like class variable) is created
Anonymous
Anonymous
Anonymous
Hussein
Anonymous
Anonymous
Hussein
Saro
Structs can also have constructors and destructors.
Adarsh
Can anyone help me why empty class have the return value 1
Adarsh
???
Anonymous
Adarsh
I mean to say why is the size of empty class is 1
Adarsh
Why it's not zero??
Hussein
Anonymous
I mean to say why is the size of empty class is 1
To ensure that an array of objects of this empty class get assigned at adjacent bytes so that they can be individually addressed. This would not be possible if the size were zero.
For ex:
class A{};
void fun(){
A obj[2];
assert(&obj[1] != &obj[0]);
}
The assertion will not fire because these 2 objects would occupy adjacent bytes. It would not be possible if the size were 0. And the reason why this is important is because the standard requires an array of objects to be contiguously allocated and to be individually addressed.
However there is an optimization called Empty Base Class Optimization (EBCO) where compilers will usually not allocate space for the base class sub object in a derived class object if the base class were empty (i.e. it has no data members and virtual functions). In this optimization, the base class subobject effectively has size 0.
Hussein
Hussein
Map
Is Codeblock good for beginners for C ?
Map
⚔️Mm⚔️ 🚫
Guys am new to c++ and am using code blocks
So now the problem is that I can't compile my code, its shows no error but I don't know why I can't get my outputs
klimi
⚔️Mm⚔️ 🚫
Yes
klimi
did you create some new project or it is just one same project and just by having some delay while compiling it is happening?
⚔️Mm⚔️ 🚫
No, Its a new project
klimi
and you were able to run it before? this project
⚔️Mm⚔️ 🚫
Yes
klimi
and you haven't changed anything?
⚔️Mm⚔️ 🚫
Yes, but am not sure if I've not temperd with anything, cause I've been going through the settings ever since
klimi
and if you create new project it doesnt work too?
⚔️Mm⚔️ 🚫
Yes
klimi
and you don't even see "compiled" or something like that?
⚔️Mm⚔️ 🚫
It shows something like "process terminated with status......" all in red
Anonymous
⚔️Mm⚔️ 🚫
Anonymous
Oh okay, how
Same way you create a text file, right click and all that
⚔️Mm⚔️ 🚫
OK thanks
Anonymous
If you have extensions hidden, change windows settings then create text document and rename extension to cpp
⚔️Mm⚔️ 🚫
I'll try that
⚔️Mm⚔️ 🚫
Kkk
klimi
⚔️Mm⚔️ 🚫
klimi
Hm, kinda not enough context to determine what is causing problems
⚔️Mm⚔️ 🚫
Anonymous
Please am kinda a bigginer in c++ so can someone please help me
klimi
Anonymous
I just need an explanation on how to use it....cuz am actually a python programer just thought c++ may come In handy
klimi
Anonymous
Ro print stuff input....use strings,floats and every thing a bigginer needs to know
Aquatica
Shubh Joshi
If I want to print a=2.06 then we are using printf("%.2f",a);
Exactly if I want to do through C++
Then How can I do by using cout?
Thanks in advance 🤙
Shubh Joshi
How can I find it on Google?
I mean by what searching?
klimi
klimi
Likit
kzxsbwvinlfh please decide this
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, is there a reason why strcmp does not return 0? So I have two strings, and a printf before strcmp shows that they are the same (given the two buffers, printf prints the same string, like "hello"). The problem is that, when doing strcmp, it does not find them to be equal. Any suggestions?
Dima
lol
习近平我肏你妈
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
yes, here it is:
printf("Questo è buff: %s e questa è string_vector[%d]: %s.\n", buff, j, string_vector[j]); fflush(stdout);
int ret= strcmp(buff, string_vector[j]); printf("QUesto è ret: %d.\n", ret); fflush(stdout);
if(strcmp(buff, string_vector[j]) == 0){
The ret value is 10, for some reason
习近平我肏你妈
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
so buff is char buff[4096] defined in the function; i use it in order to get input from stdin via fgets;
string_vector is a global array char **string_vector;
I did the malloc of string_vector in the main function as follows: string_vector= malloc(sizeof(*string_vector)*n_process));
And the output is:
1) If "hello" is in buff (what the users gave to the software) and "hello" is in string_vector then printf prints "hello" and "hello";
2) Ret for some reason is 10;
3) The if clause is never verified
习近平我肏你妈
Which platform were you using when you got this result? In particular, the standard library you were using.
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Windows 10, but I'm using WSL to compile and run the code
I don't know about stdlib, I did include though stdlib, stdio.
I guess the stdlib is glibc as the professor named it quite a few times...
I tried the software again. The problem is that the condition of "two strings are equal" seems to be 10. No metter the input string, it always returns 10 if they are equal, < 10 if the first one is minor, > 10 if the second one is greater
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
ok I think I found the problem, that seems to be a '\n' fgets leaves at the end of the first buff when taking the input
Anonymous
for(auto b = RY::Bullets.begin(); b!=RY::Bullets.end(); b++){
SDL_Rect fireballQuadO = r;
fireballQuadO.x = b->position.x;
fireballQuadO.y = b->position.y;
fireballQuadO.w*=0.2;
fireballQuadO.h*=0.2;
SDL_RenderCopyEx(renderer,fireball,&r,&fireballQuadO,b->angle,NULL,SDL_FLIP_NONE);
if(b->update(deltaTime*1000)){
RY::SDL::DrawFrame(explosionTexture,
b->finalAnimation.frame,b->position,3);
b->finalAnimation.animate();
if(b->finalAnimation.isFinished()){
RY::Bullets.erase(b); // <- error
}
}
}
Anonymous
vector erase gives compiles error
Anonymous
In file included from C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/specfun.h:45,
from C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/cmath:1927,
from C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/math.h:36,
from RYMath:3,
from test.cpp:4:
C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/stl_algobase.h: In instantiation of 'static constexpr _OI std::__copy_move<true, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = RY::Bullet*; _OI = RY::Bullet*]':
C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/stl_algobase.h:469:12: required from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = true; _II = RY::Bullet*; _OI = RY::Bullet*]'
C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/stl_algobase.h:506:42: required from 'constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = true; _II = RY::Bullet*; _OI = RY::Bullet*]'
C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/stl_algobase.h:514:31: required from 'constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = true; _II = __gnu_cxx::__normal_iterator<RY::Bullet*, std::vector<RY::Bullet> >; _OI = __gnu_cxx::__normal_iterator<RY::Bullet*, std::vector<RY::Bullet> >]'
C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/stl_algobase.h:601:38: required from 'constexpr _OI std::move(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<RY::Bullet*, std::vector<RY::Bullet> >; _OI = __gnu_cxx::__normal_iterator<RY::Bullet*, std::vector<RY::Bullet> >]'
C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/vector.tcc:175:2: required from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::_M_erase(std::vector<_Tp, _Alloc>::iterator) [with _Tp = RY::Bullet; _Alloc = std::allocator<RY::Bullet>; std::vector<_Tp, _Alloc>::iterator = std::vector<RY::Bullet>::iterator]'
C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/stl_vector.h:1431:24: required from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = RY::Bullet; _Alloc = std::allocator<RY::Bullet>; std::vector<_Tp, _Alloc>::iterator = std::vector<RY::Bullet>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<RY::Bullet>::const_iterator]'
test.cpp:123:40: required from here
C:/gcc/lib/gcc/x86_64-w64-mingw32/10.3.0/include/c++/bits/stl_algobase.h:400:18: error: use of deleted function 'RY::Bullet& RY::Bullet::operator=(RY::Bullet&&)'
400 | *__result = std::move(*__first);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~
Rasel
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n,k;
vector<int>v;
cin >> n >> k;
for(int i=1;i<=n;i++) {
if(i%2!=0) {
v.push_back(i);
}
}
for(int i=1;i<=n;i++) {
if(i%2==0) {
v.push_back(i);
}
}
//for(int i=0;i<v.size();i++) {
cout << v[k-1]<<"\n";
//}
return 0;
}
Rasel
how can i avoid time limit exceed on large number?
Anonymous
Anonymous
well, I don't think so
Anonymous
here is the class