Bumpy
char string[3] = {'a','b','c'}; char *string2 = "a"; string2 = string;
Bumpy
why its work? i know that string2 is sit on constant memory block and char[] isnt.
Anonymous
And because you just reassigning pointers
Pavel
I hope someday in C++ there will be ability to break from multiple loops (like in java), or maybe even for/else (like in python). Then there will be no cases to use goto anymore.
Vlad
Never do that
Bumpy
because i have only one character?
Vlad
what do u mean?
Easy to shoot yourself in the foot
Vlad
And doesn't make sense either
Bumpy
so u say that every time i modify "String" i need to set this array constant?
Bumpy
i know. i mean to array of char
Bumpy
or " asdasdasd "
Vlad
i know. i mean to array of char
Don't assign string literals to char*
Vlad
Also -Wall -Wextra -pedantic -Werror
Vlad
So those will be caught at compile time
MRT
Someone explain to me why this vector only gives the same objects?
MRT
std::vector<std::string> vec; static const char alphanum[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < 25; ++i) { string *temp = new string(); srand((unsigned)time(NULL) * _getpid()); (*temp).reserve(35); for (int i = 0; i < 35; ++i) *temp += alphanum[rand() % (sizeof(alphanum) - 1)]; vec.push_back(*temp); } for (auto &c :vec) { std::clog << "its c: " << c << std::endl; }
Pavel
srand need to be done once in the beginning (of the app, preferably)
Pavel
fixed :D thanks :Xxxx
And about allocating std::string that was a good point ☝ You better to create it on stack to avoid unneded allocations
MRT
Why do you allocate std::string on the heap lmao?
I'm not familiar with these terms yet, can you explain more rudimentarily
Vlad
I'm not familiar with these terms yet, can you explain more rudimentarily
Heap allocation is needed only when: 1) size is unknown at compile time 2) object(array) is too large to be stored on stack 3) you store object as a pointer in some container for polymorphism
Pavel
I'm not familiar with these terms yet, can you explain more rudimentarily
Don't do string* temp = new string(); do string temp; instead
Vlad
And to put it very crudely. std::string is a heap allocated array of char. So basically you're allocating container internals
Vlad
For what reason in particular no one knows
MRT
Excellent, thanks for the explanation
Eturnus
Somehow my file handling progrm is not opening file in output which should i change in my progra to fix error //File handling #include<stdio.h> #include<conio.h> int main() { FILE *fp=fopen("//storage//emulated//0//Download//sample1.txt","r"); char ch; ch=getc(fp); while(ch!=EOF) { printf("%c",ch); ch=getc(fp); } fclose; getch(); }
Eturnus
ORTIFY: getc: null FILE* showing in output of my phone
Eturnus
Please explain
Vlad
Try to run as sudo
>sudo >conio.h
Vlad
Why do they still use conio.h for God's sake
Vlad
?
ms dos header file lol
Eturnus
Ooh it was already written in my app when i opened it so i didnt changed
Vlad
Also are you sure that it must be double slashes?
Eturnus
Also are you sure that it must be double slashes?
I just copied file location and pasted here
Eturnus
Et me try single slashes
Eturnus
Is is saying same thing
Eturnus
FORTIFY: getc: null FILE*
Pavel
show the output of ls -l //storage//emulated//0//Download//sample1.txt
Eturnus
show the output of ls -l //storage//emulated//0//Download//sample1.txt
Int this file something is written i am unable to read it😁 See Utilitatis causa amicitia est quaesita. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Collatio igitur ista te nihil iuvat. Honesta oratio, Socratica, Platonis etiam. Primum in nostrane potestate est, quid meminerimus? Duo Reges: constructio interrete. Quid, si etiam iucunda memoria est praeteritorum malorum? Si quidem, inquit, tollerem, sed relinquo. An nisi populari fama? Quamquam id quidem licebit iis existimare, qui legerint. Summum a vobis bonum voluptas dicitur. At hoc in eo M. Refert tamen, quo modo. Quid sequatur, quid repugnet, vident. Iam id ipsum absurdum, maximum malum neglegi.
Eturnus
I downloaded a txt file and linked it to program
Eturnus
Ok
حماد
Can anyone tell me which one is the best IDE for C++..
Pavel
Ok
And btw, are you running on Android? You path looks weird
Pavel
Yes android
I'm not too familiar with running native code on Android. How do you compile it? Cross compilation?
Eturnus
I am using coding c app and running on it
Anonymous
I was close
Eturnus
I am able to run that program bit it's not accessing the file i linked to it
Pavel
I am using coding c app and running on it
Does this app have a permission to read this dir?
Eturnus
Yes, because i have moved my file to the folder where this app saves his program so i dont think i get trouble in accessing
Pavel
Yes, because i have moved my file to the folder where this app saves his program so i dont think i get trouble in accessing
Then I dunno, try to use OS API to open this file, it gives you the exact reason why it can't be opened
Eturnus
Ok
Pavel
In multithreaded environment, how do you guys protect yourself from accessing something from a wrong thread? Do you make every peace of your code thread safe? Or how do you deal with it?
Anonymous
#include vs import
ninja
#include vs import
https://stackoverflow.com/questions/172262/c-include-and-import-difference ,, do google first
Igor🇺🇦
In multithreaded environment, how do you guys protect yourself from accessing something from a wrong thread? Do you make every peace of your code thread safe? Or how do you deal with it?
Try minimising shared resources. There is no point in having lots of threads when they spend time on waiting resources. Access those that need to be shared through defined set of accessor methods or create a class with the sole purpose of controlling exclusive access to them.
Lava
/get
Lava
int main () { if( sizeof(int)> -1) cout<<"yes": else cout<<"no"; return 0; }
Anonymous
How is this displaying no
integer promotion
Igor🇺🇦
int main () { if( sizeof(int)> -1) cout<<"yes": else cout<<"no"; return 0; }
size(int) is of type size_t ( unsinged ) , -1 casted to itis max uint. Using 0 returns "yes". https://onlinegdb.com/BJZI-iS-_
Lava
For say 4 bits ?
Igor🇺🇦
So -1 is casted to 9 ?
But your platform is not 4 bit one. Whatever 11111... means
Lava
So max of whatever bit rate my platform is ?
Lava
Got it . Thank you so much !