...
change the for(auto ...) "auto -> char"
expression must have class type but it has type "char"
...
It's showing an error now
klimi
std::vector<char> has chars inside, not classes
klimi
for(char it:vect)
...
Oh okay
...
Now I feel dumb
klimi
Now I feel dumb
don't be, I am not sure why it isn't getting char from the context myself
Chat Boss
Anikalp Jaiswal sent a code, it has been re-uploaded as a file
...
Actually take a look at this I want result as a 2 b 3 c 3 but instead of this it's resulting into something absurd
klimi
You created vect as std::vector<int> so... it's not char but it's int; that's why it printed the numbers the first time
klimi
you will have to print the pairs if you want that (you need char and int for the character and the int)
...
Yeah, so do you have any idea to how copy values of a map to a vector in such situation?
klimi
Yeah, so do you have any idea to how copy values of a map to a vector in such situation?
I don't see the need to copy the values; if you really need to copy them, copy it into a std::vector<std::pair<char,int>> or something
...
Oh okay, yeah, actually this is just a part of a problem I have to solve it further.
...
Thanks for helping me out
klimi
Oh okay, yeah, actually this is just a part of a problem I have to solve it further.
you can just "cout" more things when you iterate through the map at the end
...
Oh okay, I got your point
Anonymous
Not in a declaration (in this case parameter declaration). Node *&r means r is a reference to a pointer to Node. Btw this code is invalid in C. C does not have the concept of a reference.
Anshul
i am trying to add #ifdef inside a function parameter list. but i am getting error. Is it allowed to do something like this A fun( int a, double b, #ifdef newPlatform vector<someStructType> c #endif) { <fun defn> }
Anonymous
i am trying to add #ifdef inside a function parameter list. but i am getting error. Is it allowed to do something like this A fun( int a, double b, #ifdef newPlatform vector<someStructType> c #endif) { <fun defn> }
No this is not allowed. If this were allowed, it would violate the ODR (One Definition Rule) where functions can be have different meanings in different translation units depending on preprocessor macros. Only evil can come out of it.
Anshul
ok so is there any way to do it? I don't want to create seperate functions for different platforms.
Anshul
ok
Chat Boss
010001010111001001100100011001010110111000001010 sent a code, it has been re-uploaded as a file
Arch
i have created a snake game program, runned the compiler with no issues but i cannot see the game output, just black window
Arch
do your computers output the program?
Anonymous
/start@MissRose_bot
Arch
010001010111001001100100011001010110111000001010 sent a code, it has been re-uploaded as a file
can you just at least check if the code is running and you see the the game?
Chat Boss
Ulyana Andreieva sent a code, it has been re-uploaded as a file
Uliana
Who knows how to do that, with pointers, but without fstreams?
B
Is there any CTF like exercises for C/C++?
Anonymous
PS C:\.dev\project\trycmake> cmake .\CMakeCache.txt CMake Error at CMakeLists.txt:4 (project): Running 'nmake' '-?' failed with: The system cannot find the file specified CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage -- Configuring incomplete, errors occurred! How to set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER?
ynwqmv
how to include boost library in cmake?
Anonymous
how to include boost library in cmake?
Use find_package command. Cmake comes prebuilt with modules that enables searching for commonly used packages like boost, opencv and all. Just search for it online.
Anonymous
Do you have nmake on your system?
Now all works good, I few times type a cmake and make and everything start work
Anupam2.7
I am getting a wrong answer error on a chdechef's problem, later I noticed that it is behaving different in printing a expression directly and printing it by putting it in a variable. i.e. int ans=inc-2*(0.2*inc)-0.3*inc; cout<<n is acting different than cout<<inc-2*(0.2*inc)-0.3*inc; Why is it happening?
Anupam2.7
already tried. same wrong answer error. This is the question: https://www.codechef.com/problems/SUGARCANE?tab=statement This is the code: https://pastebin.com/HnLZHBH3
Anupam2.7
what do you mean?
Anupam2.7
try casting it to int
worked 🫡 What datatype is it earlier, why is it happening?
Anupam2.7
float?
Suka
float?
yups or double
Anupam2.7
Anupam2.7
yups or double
then why is it working for other test cases?
Anupam2.7
leave it, got it. thanks
Suka
then why is it working for other test cases?
idk. usually when your formula contain fractional part it get casting to double.
itsmanjeet
can i remove values from vector while iterating to it like for (auto i = vec.begin; i != vec.end; i++) if (!i->marked) { vec.erase(i); } }
On
Please I need a C++ beginner project work questions
neon 🇮🇳
Any C++ Projects Crowd Source project where I can contribute in GitHub?
Modern College
Hey guys I'm working on a code and i need a bit of help in this there's a switch statement is is being assessed to call various function what i want to do is after the function is used i want to to return to switch in main function and run it until i choose to option to exit can anyone help?
Modern College
in which loop and how theres where im getting problem
Ziky
Could you put your code into gist / pastebin and post link here?
Ziky
I guess you need something like while(1) { switch(getch()){ case 'a': do_a(); break; case 'b': do_b(); break; case 'x': return 0; } }
Ziky
Btw I am on tablet and ghis was the simplest thing what came to my mind I am not sure if getch() even exists. Consider it as example of logic, not as working example
Anonymous
I
Why are you reviving old posts?
AlanCcE
Btw I am on tablet and ghis was the simplest thing what came to my mind I am not sure if getch() even exists. Consider it as example of logic, not as working example
If he is using C, it has the lib 'ncurses' which has the getch() function https://pubs.opengroup.org/onlinepubs/7908799/xcurses/curses.h.html
Ahmed
Is C better than C++ in embedded systems generally? Also does anyone still use assembly language or is it that they all now depend on the compilers concerning embedded systems design and peojects
AlanCcE
Is C better than C++ in embedded systems generally? Also does anyone still use assembly language or is it that they all now depend on the compilers concerning embedded systems design and peojects
Im not a specialist in the subject, but i think this like anything depends in the system requirements C can be more 'lightweight' compared to C++ so you can probably make systems consuming less memory and process power. So if you want to make a lighter system probably C would be better, but in something like a phone like the buddy above said C++ would be better (?). Anyway, feel free to test stuff and focus in which approach should solve the problem properly. (If i said some shit feel free to correct me)
布丁
I think most of the time what language to use depends on the toolchain provided by the OEM
布丁
Some uses a tailored c/c++ compiler with a broken std but u have no choice
Rosemary
Hello
Rosemary
New to C, any mentor ? 🙏
Ziky
New to C, any mentor ? 🙏
For How much money?
Ludovic 'Archivist'
🙃
How do you read a file passed by main from a function? example : void function (FILE *f) { }
🙃
int main() { funtion (stdin); }