If you aren’t very familiar with C++, my advice would be to admit it at the outset. Modern C++ is a huge, complicated (and often convoluted) language and they will be able to poke holes in your seeming expertise unless you admit it at the outset. I’ve interviewed people who claim to be a 9 out of 10, but if that is the case you should probably know most of the standard by heart.
That out of the way, I would say that Bjarne’s “Tour of C++” is a great read that can easily be done in a week (I did and I wasn’t cramming for an interview). It gives a nice introduction to modern C++ features for a well-versed programmer coming from another language: https://www.amazon.de/Tour-C-Depth/dp/0321958314
Other comments have covered your specific issue, so I'll just give you some advice about rand. Don't use it. It suffers from some serious problems, and the new C++0x standard has better methods for generating randomness. This video covers it's issues well, as well as how to use the new <random> library which replaces it.
1 and 2: - try with easy problems on leetcode.com
3:- you can become software developer, game developer, os driver developer(since u pickedup C++), data scientist ..etc
good luck on your journey
It could be due to thread safety. C++ guarantees thread-safe initialization of static
local variables, and that inserts a chunk of code. -fno-threadsafe-statics
will get rid of this (but now your code might not be thread safe, so be careful).
There's other reasons a static will introduce a bit of memory overhead. For example, if the object has a constructor the compiler needs to make sure it only gets called the first time the function is called.
If you need to dive into this a bit further, Compiler Explorer is a good tool.
Why not just go all the way and do something like this?
Constructors and destructors are cool. My knowledge of C++11 is pretty much nonexistent (I've been living in Pythonville), but I'm sure you can do even better.
Lippman - C++ Primer 5th edition. A great comprehensive look at everything in C++ aimed at programmers with prior experience. I worked through it this year and was very impressed. There are exercises every few pages so you can really understand what you've just learned.
I can't recommend enough picking up the latest edition (4th?) of The C++ Programming Language. It goes through most of the changes to the language and the STL that have occurred in C++11. C++14 has brought even more, but they are minor in comparison. Suffice to say it's a whole new language, and the vast majority of changes have been for the better.
Perhaps the most surprising of all, ICC is no longer king of the compiler hill; it was surpassed both in performance and compliance quite a while back by GCC, and the recent language revisions have only exacerbated that. Meanwhile, Clang came in and swept the community off its collective feet, though time will tell whether it displaces GCC or they end up living in harmony. MSVC lags behind as usual.
Using rand() in C++ is terrible, and this guy can tell you why: http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful
The gist of the presentation is that the std library offers much better functionality than rand() which will do exactly what you want whereas rand() cannot.
It looks like your list is a subset of the Definitive List. Also, C++ Primer Plus is explicitly not recommended because of its antiquated approach to teaching C++.
IMO, to get a job for a Senior C++ Developer position you need a very strong knowledge of implementing common data structures and algorithms in C++ since you will need to demonstrate that during the interview.
To acquire that kind of knowledge you should take university courses in data structures and algorithms or failing that take a online course like this one on Coursera:
https://www.coursera.org/course/algs4partI
In this course, all the algorithms are implemented in Java, so converting them to C++ will also help you learn the language.
During the interview they may ask you to implement things like linked lists, queues, stacks, different kinds of trees, etc.. So having good knowledge there is important.
Now as far as how to be successful as a C++ programmer besides just being good at writing C++ code you need to have a good understanding of issues with memory management, debugging, and know how to find and use libraries and test your code.
Good luck!
EDIT: I recommend you set up a github account, and as you implement these data structures and algorithms check them in there, that will also help you become familiar with using git and give you a little bit of a github activity history which will look very good to potential employers.
System wide? That's asking a lot and is way past what making a piano program in Java involves.
Why not see about fixing a bug or working on an existing project like that?
Here's the first thing that came up on Google: https://sourceforge.net/projects/equalizerapo/
If you want to build something from the ground up to learn, there are a lot of better options, but a system wide equalizer isn't trivial. I imagine you'll spend more time banging your head around idiosyncrasies of your platform than actually doing anything useful.
Since you're very new I would suggest first go through sololearn.com and follow through their tutorial. This will make you familiar with the syntax.
Side by side, try out a few programs. You'll get a lot of errors, use stackexchange (most of your doubts will be available).
Then you can also try HackerRank's tutorials, they teach you by giving problems https://www.hackerrank.com/domains/cpp
This will make you familiar with the language and the process of writing a program.
Once you finish this, you can post again on this subreddit because you'll have a good understanding of how do you want to use this language.
Good luck!
Yeah, you're overthinking this.
The "this" pointer is nothing more than an implicitly included parameter to a member function pointing to the object that the function was called on.
E.g.
{ MyCppObject myObj; MyCppObject *myObjPtr = &myObj;
myObj.PrintMyInt(); }
void MyCppObject::PrintMyInt() { // (uintptr_t)this == (uintptr_t)myObjPtr // typeof(this) == MyCppObject* printf("%d\n", this->myInt); }
Why would you want to use it? https://stackoverflow.com/a/2828891
Xcode supports the Clang and GCC compilers. Both are modern, mostly up to date with the latest versions of C++, and open-source.
Please note that Xcode is not a compiler, but just an IDE.
For more information on how to install the GCC compiler, follow the Xcode Command Line Tools.
A quick edit/addition: if you find yourself preferring the feel of Visual Studio and happen to be looking for a similar editor on macOS, you can get Visual Studio Code.
I'm a little confused by what you mean, but you're using a mac so this should help you get the .app that you would share, https://stackoverflow.com/questions/1984727/how-to-get-app-file-of-a-xcode-application and with the text file, use a relative path instead of exact
This is a classic "pick one" scenario I'm sorry to say. Graphics with C++ is blood from stone territory.
If you just want a simple Visual Basic style form with fields/drop down boxes/etc. probably use the Visual Studio MFC editor is your path of least resistance.
(https://stackoverflow.com/questions/20335066/mfc-wysiwyg-editor)
Don't let the inner class be a template as well:
template<typename T> struct foo
{
struct bar
{
T* _;
};
};
foo<int>::bar x;
A container of type std::map<X, Y>
stores a series of key-value pairs, where every key is type const X
and every value is type Y
. It's not possible for there to be a mixture of key types or a mixture of value types.
However, you can define a type that represents a union of several types. If you store some information indicating which of the possible types each instance really is, then you have a discriminated union. Look at Boost.Variant for a common example. If you want a map where keys are integers and some values are std::string
and some are double
, you could do that as:
std::map<int, boost::variant<std::string, double>> container;
But of course this complicates the iteration a bit because p->second
acts like a pointer to boost::variant<std::string, double>
, not like a pointer to std::string
or a pointer to double
, and you'd have to use the Boost.Variant means of accessing the value, e.g. either through a visitor or through .get
. In other words, the map parts of the code always return a single value type, it's just that you can use a value that represents multiple types.
Doing one big allocation up front is always going to be faster than resizing a std::vector
or such, since each resize (usually on every doubling of the number of elements) involves another memory allocation and copying all the current elements to the new location. Going through the file an extra time to count the elements doesn't hurt as much as you think it should either, as (assuming you have enough RAM) the whole file ends up in your disk cache making subsequent reads much faster (pretty much just syscall overhead). That doesn't mean you have to give up the benefits of std::vector
for performance though - just call reserve(count)
on your vector where you would allocate the array.
Of course, you can avoid going through the file twice if you can add a header with the number of entries. If you have complete control over the file (you don't have to parse files that come from other sources), you could even consider writing the entries in a binary format that you can use directly after mmap()
ing the file into your address space. Boost.Interprocess's memory-mapped file support can help you achieve this in a portable, object-oriented fashion.
Can you show what you did to fill the bitInfo struct? I'm asking because I have a feeling you are trying to write 24 bit color data to something that actually expects 32 bit color data.
If it isn't that, have a look at this page, in particular the section headed "Remarks":
>The bits in the array are packed together, but each scan line must be padded with zeros to end on a LONG data-type boundary.
That means that every line in your picture needs to be some multiple of sizeof(LONG) in length. If you don't do that, you'd expect behavior like you see in your picture, that every line after the first is shifted by a certain number of pixels.
edit: Actually, while I'm here, have a look at Allegro. From your screenshots I get the impression you're working on something at least game-adjacent. Low-level Windows graphics is complete garbage to work with for exactly the sort of reasons you're running into. Unless your specific aim is to get to know a rarely-used platform-specific API in frustratingly detailed ways, I recommend using some library to take care of the technical details so you can focus on getting interesting things done.
Homework is much more fun than the boring business code i should be churning... I guess what you are asking is command line arguments. You can access them via the arguments of main function.
Try source trail https://www.sourcetrail.com/ and try to draw a picture of the class you understand somewhat. For example you could look at the inheritance hierarchies, or order of construction.
Add some debug messages to it, run it, see how to behaves.
It doesn't really matter in which order you do it, the more time you spend reading and playing with the source code, the more you get familiarity with it.
Gr,
Jan
> I didnt look on the link. Correct me if im wrong.
> So you need some string args that you will call them the words you want. I mean the arg[] command.
> arg[//some words here] i think this is how you do it.
> Then you use the rand() command something like this.
> rand(arg) ].
> As i said first, i am a begginer at c++ so i am not sure if it is very good, but i hope you understand me.
Nope. Try it and see where you're off - you're confusing functions, arrays, and arguments.
https://devdocs.io/cpp/numeric/random/rand
rand() generates an integer, not a string, and takes no parameters.
arg[] is not a command. int argc, char** argv are the two arguments passed to main() from the command line. argc is the number of arguments, argv are the arguments themselves (with argv[0] being the command used to execute the program).
Answers to the question of how to generate a random string of characters can be found here: https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c
There's actually a lot of good material out there for learning C++, it's just that the good stuff isn't free, and the free stuff is not very good. The hardest part is the semantics. I would strongly discourage learning Java or C# first if what you really want to do is C++. You will pick up a lot of bad habits with the reference semantics of those languages.
For a traditional path, C++ Primer by Lippman, et al. is good, I would avoid Deitel & Deitel. There is a lot to be said for Accelerated C++ by Koenig for a more non-traditional approach. If you already have the syntax, you can't go wrong with Scott Meyers' books, he has a great way of pointing out the traps and giving you the right way to approach an issue.
Absolute C++ 5th or 6th edition by Walter Savitch as a learning companion and then The C++ Programming Language fourth edition by Bjarne Stroustrup as a reference manual and advanced learning. It is my bible as a c++ tutor. He is credited as the creator of the language.
In all the tutorials, programs and sources I've looked through, declaring was always specifying a data type and then the name. For instance:
int num;
Or:
Those two items are declarations of a variable and functions respectively. I've not seen it unlike that anywhere else, except in exceptional circumstances. If you can give us a link or book name for some context, it'd help. I think you stated this was in C++ Primer?
If you're looking for a textbook there's this webpage I came across recently which I wish I had when I was first exposed to the language, you may find it helpful. Link Apart from this: C++ Primer and Accelerated C++ are pretty good books if that's your jazz. Bucky's tutorials are nice too, freely available on youtube.
I tend to recommend C++ Primer[1] to anyone who has some basic C knowledge. It is a big book but very through. It is well respected by many well known C++ programmers.
If you find C++ Primer a bit tough and fancy something a little easier to grok personally recommend Programming: Principles and Practice using C++. It is written by the man who first developed C++ and is truly excellent albeit very dense as it is designed to be used as a university textbook/course. It is superb though. Some other quite enjoyable beginner C++ books are - Learning C++ by Creating Games with UE4 and Jumping into C++
[1] http://www.informit.com/store/c-plus-plus-primer-9780321714114
True, the blog writer seems to be rabid, but having viewed newboston's videos myself, I have to agree with it.
> > If you don't know about [RAII], you are not good at C++. If a tutorial does not introduce it, it does not cover C++ well.
> The first point is fallacious - I know PhDs who teach computer science for a living who don't know about the latest C++11 features - but yet they could still kick my ass in programming. If you made this claim at any serious programming conference - I'm sure you would not get invited back.
Erm, RAII is not C++11, it has been a part of C++ for a long time (some might even say its inception). The only "feature" you need to use RAII is construction/deconstruction -- something C didn't have. RAII doesn't have to be this big complicated thing, but it is vital to being a good C++ programmer. RAII doesn't refer specifically to the smart pointers, it also refers to semaphores, mutexes and other resource acquisition concepts. I would argue that your PhD friend likely uses RAII all the time, even if you or they do not know that they are.
Further, in a thread about getting C++ tutorials, I would argue that one definitely shouldn't use an old book for starting out. A newbie should start with a good book that covers the latest standard (C++11), like C++ Primer 5th Edition (Note: NOT C++ Primer Plus)
If he's just starting out, I suggest you push him to learn programming concepts and the C++ language first, and to learn them well, before attempting game programming. To that end, any of the books on this list are good. You can pick ones appropriate for his skill level. C++ Primer and The C++ Standard Library are possibly the most useful for beginners.
I really liked working through Peter Norvig's free Udacity's class Design of Computer Programs. It's in Python (and you'll have to submit Python answers to progress), but you can also work through it implementing the code in C++ and checking your output against the Python output. Peter's thought process through the development of a poker game is really very engaging and interesting and it's like getting a class from one of the true masters of programming.
https://www.udacity.com/course/design-of-computer-programs--cs212
Here is a chart with the solution. I suspect this could be extended out as far as you want. You just need a supercomputer built out of raspberry pi's. (or leave your computer running when you leave the house)
zero 43 57 -56 -44
one -44 -12 57
two -35 81 -44
three -35 -20 -56 57 57
four 62 -44 42 -56
five 62 -24 -90 57
six -5 -24 35
seven -5 57 -90 57 -12
eight 57 -24 30 -20 -35
nine -12 -24 -12 57
ten -35 57 -12
(Numbers next to words are assigned to corresponding letters in the words)
This is the same program I wrote that solved the problem: http://ideone.com/3Gbjjr
You can always just change the compiler for NetBeans (afaik). Get a MinGW Builds package and change the compiler location somehow.
/u/boredcircuits makes a lot of good points. Why not just develop on your mac in a virtual environment? That's what I do for some classes.
VirtualBox is free.
You can use something like onthehub to see if your school offers any free software - I can get a Windows 10 license and Visual Studio Enterprise license for free through my CS department.
Set up a virtual environment for Windows 10/VS and code in there.
CMake always gives me a headache, that's why I wish CLion had the option to use GYP.
I don't use Windows regularly but I'll try and help. Try using the add_library(glew) command. you should specify whether you want GLEW to be a static or shared library by using STATIC or SHARED in the add library command. I think everything else is correct.
I've never used OpenGl directly, but this might help.
If none of this works, sometimes I try building the library I want to link, before using it to make sure there are no problems.
I bet this Hacker News comment explains it correctly:
> It looks like clang creates it's data structure representing the template instantiation, caches the instantiation for the parameterizing types, then begins instantiating the types for the members. When it first hits the static bool, it reserves space for it's static value, then recurses into the static bools type in order to determine the value. Since the recursion uses the same parameterizing types, it finds the type it was midway through constructing, finds the space-reserved-but-no-appropriate-value-set static member in it, takes a 0 from that memory ( presumably from having allocated and zeroed the memory when initially saving space for the final value ).
The concept you are looking for is partial function evaluation. There are plenty of ways to implement it in c++ pre c++11. Boost has a good implementation of it that works in most earlier c++ versions.
You can also implement it yourself on a case-by-case basis as a functor if you desire. You store the bound parameters as member variables and call the original function in operator()
. An informal example would be:
double f(int a, int b);
struct bound_f{ int p_a; bound_f(int a) : p_a(a) { } double operator()(int b) { return f(p_a, b); } }
bound_f bf(1); bf(2); //identical to calling f(1, 2)
I would advise against a vector<bool>, there is never a use case for it and it's likely to get removed from the C++ standard in the future.
boost::dynamic_bitset solves the problem of a variable number of booleans:
http://www.boost.org/doc/libs/1_55_0/libs/dynamic_bitset/dynamic_bitset.html
Most people here seem to be suggesting solutions which output images at each stage of the program, which from reading your question is not what I think you are looking for.
If you are looking for a simple means of drawing stuff on the screen then you could use SDL or SFML. I haven't used either but both look fairly simple and similar. SDL is written in C and (obviously) has a very C like api, and SFML is written in C++ and the API might be more obvious to somebody who is more comfortable with c++.
SFML: http://www.sfml-dev.org/
Try reading this http://www.mingw.org/wiki/specify_the_libraries_for_the_linker_to_use
also codeblocks uses mingw, so this may have some useful info for you http://www.sfml-dev.org/tutorials/2.3/start-cb.php
I don't know where to start:
> set an allocator for your containers. It'll make your life easier when optimizing or tracking down bugs.
I would disagree with this. Recommending the use of an allocator to someone who asked specifically if the code was idiomatic C++11 is over the top. If anything, the use of an allocator is the corner case.
Plus, I see the reply down the page a ways that says its for optimizing and debugging memory. First, remember the rule-of-thumb "avoid premature optimization" (http://herbsutter.com/2013/05/13/gotw-2-solution-temporary-objects/). Second, for memory debugging there are excellent tools like the Clang's Memory Sanitizer (http://clang.llvm.org/docs/MemorySanitizer.html) that I'd recommend over a roll-your-own if at all possible.
If you intend to use OpenGL for graphics processing, I would strong strongly encourage you to use OpenSceneGraph. It's a very rich and finely tuned API for OpenGL which takes advantage of the object orientation of C++. I've tried using OpenGL and GLUT directly before, and it's a nightmare even for an experienced programmer.
On the other hand, if you intend to use DirectX rather than OpenGL, then it's not too bad. I would prefer the object oriented aspects of OpenSceneGraph over the buffer swapping style of DirectX, but I can't deny that DirectX has much better Quality Assurance than OpenGL could ever hope to have.
Another thing you might want to look into is OGRE. I haven't used it myself, but I know it's very popular, and I understand that it works similarly to OpenSceneGraph.
Here is a basic implementation of shuffling with plain arrays:
It would be bit simpler with a datastructure that has easy removal of elements.
edit: here is another which does bit more copying but avoids pointers http://ideone.com/qX7FNH
I would say, since you're a semi-experienced C# dev, try converting some of your C# stuff to C++, and then try to figure out what isn't working. That's what I did doing the Project Euler problems in a certain language.
Also, I just usually go to http://www.tutorialspoint.com for quick refreshers, and also if I forget how a loop works from language to language.
Sorry if this isn't helpful enough (I'm fairly new to C++/Programming myself), but it sounds like you want to set objects equivalent to other objects and would potentially do so by overloading your assignment operator. Take a look here: http://www.tutorialspoint.com/cplusplus/assignment_operators_overloading.htm
I used to use Dash before i started to remember enough not to have to read the docs so often: https://kapeli.com/dash
​
It was _great_ .- there's a windows equivalent I think
It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!
Here is link number 1 - Previous text "Lua"
^Please ^PM ^/u/eganwall ^with ^issues ^or ^feedback! ^| ^Delete
At my school we worked through Problem Solving in C++, which is a really good book on the language. Learning to write classes, data structures, and using separate files in one program is covered in the book, and is pretty crucial to working on big software projects.
If I understand your question, and assuming you're using visual studio, the exe file that is made when you run your code is located in the debug folder; you generally can run it outside of your IDE. There are better builds you can do, but that's the easiest one.
I used C++ Primer 5th ed. to learn C++ this past summer, and I found it to be very helpful. Found it on a recommended book list on Stack Overflow, which another commenter linked. While there are a few chapters covering basics, the book explores the meat of the language quite well. Bonus is that it covers up to C++11.
The best way to learn C++ is using a book. Some the best C++ books for beginners are: Programming: Principles and Practice Using C++ (By the creater of C++, an excellent read) C++ Primer Plus (Some people argue against this book, but I own it and it is very good) C++ Primer (Not the best if you are brand new to programming, but one of the best books)
If you already know how to code and want to learn the language, C++ Primer 5th Edition by Stanley B. Lippman is a great place to start. Two core books as you progress into more advanced C++ programming will be The C++ Programming Language by Bjarne himself, and for the library The C++ Standard Library by Nicolai Josuttis. You probably want to get a book about GUI programming, if that's a direction you want to go in outside of console applications, and I think that Qt is, personally, one of the best GUI wrappers to use. Book? C++ GUI Programming with Qt 4 2nd Edition by Jasmin Blanchette. Hope this helps.
Stroustrup's The C++ Programming Language (4th edition is the latest I believe) is a great way to learn your way around many of the newer language features and additions to the standard library without having to sift through Modern C++ blog posts and language tutorials from 2001. N.B., however, that it is not a beginner's guide; it expects you to be a programmer already, and it assumes some prior knowledge of C99 and C++98. Meyers' Effective C++ books are timeless; he wrote a new one for the new language standard, and most of the old books' advice remains sound. Due to the way he wrote them, it's worth picking up all four. I would also strongly suggest you check out the videos of the CppCon 2014 and 2015 presentations, which include talks that cover all sorts of subjects, from the most basic to some wildly advanced. You can find them on MSDN Channel9 or their YouTube channel.
Stroustrup's The C++ Programming Language, 4th edition, provides an excellent overview of new language and library features introduced in C++11, and it's geared toward a programmer who is already familiar with the 1998 standard. Scott Meyers' Effective C++ books are still fantastic resources, and he wrote an entirely new one for C++11 and C++14. The CppCon 2014 and 2015 presentations and slides are also available on MSDN's Channel9 and their YouTube channel, and they cover a broad range of topics, but there are a handful devoted to modern C++ best practices and getting yourself out of the "legacy" mindset.
The "standard responses" are:
I now would wholeheartedly recommend Accelerated C++ even though it's not yet on the current C++ Standard.
It makes up for that primarily by the right mindset: skip historic baggage, skip how C++ evolved, and focus on the things you need to write code now.
AccC++ will not teach you all there is to know about C++, but it will teach you how to use it well.
(Another advantage over the primer: weight.)
I don't know any real beginner books. And even if I did recall any, they'd be far too outdated now.
I don't know if its been updated for the latest C++ standards, but way back when I was learning C++ I found Meyers's Effective C++ to be great. It won't teach you the language basics, but it does a great job of describing the common "gotchas" of C++ that will trip you up and how to avoid them. It is also a brief read.
Sutter, Josuttis, and Alexandrescu all have excellent books on various topics.
For advanced learning the old standard was Stroustrup's The C++ Programming Language. But I wasn't impressed with the latest edition. There are probably better books out there.
You should start by googling for a simple "C++ for C programmers" or "C++ for Java developers" online tutorial.
I started by taking C, then when I transitioned to C++ I used:
Both great books, Accelerated C++ is a nice transition if you know some C.
Primer is a complete resources which is around 1k pages and it covers most aspects of C++. Get both these books, and just work on programs. That's the only way to learn quickly
I did think you would might find Accelerated C++ a bit difficult when I saw you had bought it. To be honest it isn't a book for beginners. Sure it is a great book if you already know another programming language well and want to get up to speed with C++ quickly but as a beginner to programming it isn't a good book to pick. Same with C++ Primer. A lot of people also hate on C++ Primer Plus (a different book to C++ Primer which causes a lot of confusion) as it teaches in a more C-style C++ than people like these days. It isn't actually a bad book though. Like I said in my other post programmers love to hate on certain books.
A lot of people suggest Bjarne's book 'Programming: Principles & Practice using C++' but personally I found that book to be just average. Bjarne isn't the world greatest technical author I am sorry to say.
If you are looking for a book that will teach you about programming while learning C++ probably the most accessible book will be Jumping into C++ by the guy who runs www.cprogramming.com, it isn't the best book available and it has some crappy bits in it but overall it is quite nicely written and introduces you to programming and C++ quite nicely. You can get the ebook from his site or a dead tree copy from Amazon. Also if you are on Windows and using Visual Studio I personally quite enjoyed Beginning Visual C++ 2012 by Ivor Horton. It is a big book but it is quite decent and covers a lot of things about Windows programming that other books won't cover. This is both good and bad :) Good if you want to develop for Windows obviously but also bad because it takes you away from core C++ and into things like MFC and C++/CLI. If you want to have a one to one chat about some books feel free to message me.
About your code, they're 2 points I'd like to make:
extra data: http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/
How std::cout works in c++ : std::cout << "a " << "b";
std::cout << "a " will output std::cout so the order of evaluation will be: ~ 1st: (std::cout << "a ") and return std::cout ~ 2nd: std::cout/the returned cout above/ << "b";
~~~> getAcctName() returns a std::string std::cout << getAcctName(); is like std::cout << "string returned by getAcctName()" ;
and
printAcctInfo() returns a void, so
std::cout << void(no type in this case); -> not cool mate :- (
solution:
either don't use: std::cout << printAcctInfo(); // but simply call printAcctInfo();
or make printAccInfo take a ostream object and make it return a ostream object. its definition: ostream& printAcctInfo(ostream &o ) { return o << name << " is " << age << " years old." << std::endl; }
there might be a bit less intuitive and direct solutions, lets see
You might want to consider learning about parsing. This book is a decent introduction to some common tools used to do that. They help you generate source code for doing the task.
don't know what the problem is then, it compiles and runs fine on my Visual Studio 2019
runs here too https://repl.it/repls/EarlyLiquidMotion
you must have linker setup problems. its not the code. paste the error output
I was curious, so I wrote a total hack of a bash script to recursively list all the dependencies of the Ubuntu build-essentials
and vim
packages, deduplicate said list, then get and sum all the package sizes...
On 20.04 - ~86 MiB. That's GCC, GDB, standard library, documentation, make, other tools you'll never use, a popular editor, and their combined dependencies. It's almost everything I've ever needed across a 16 year career. Can't really think of more that wasn't a project dependency. Maybe Valgrind or CMake...
So I dunno, man... lol. I've no idea WTF Microsoft is doing to be so bloated. Maybe just install the build tools instead of the IDE? I've no idea if that would slim down the footprint. You would have to install your own editor, and you'll need integrations that are aware of the command line toolset.
I read your question over in the C programming Reddit, and based on your more thorough explanation of your needs over there, I would recommend https://www.amazon.com/Sams-Teach-Yourself-Minutes-2nd/dp/0672324253/
I think this question on SO will give you some resources to start with.
You will have to at some level interact with the sound card drivers. They exist to provide a consistent interface to audio devices to windows. If what you are trying to read is not actually an audio signal, then you should explore building a different device with a different communication medium (e.g. using an arduino / raspberry pi or its kin).
Additionally, I'm not sure how much signal processing you have done, but (roughly) all methods you use will give you an "amplitude over time" sort of signal. If you need frequency information, you are going to need to do some work to get it.
Disregard the two answers already given. Bellow are the only two links you'll need to learn C++.
> Can the GUI for the COMPORT and the 3D enviroment be put in one Windows? Doesn't have to be one project necessarily.
Yes - you can have an OpenGL context that does not take-up the entire window. Here is the first google hit on this topic (warning, old): http://www.codeproject.com/Articles/16051/Creating-an-OpenGL-view-on-a-Windows-Form
> What kind of template should I use for the COM-GUI? There is a windows forms template by "Isak Âgren", should I use that or is there something better?
I'm not sure what you mean here. I do not know your requirements, what kind of functionality you want, etc. If it were me, I would just create my own GUI using simple "WinForms" controls.
> If I should use two seperate projects, what template should I use for the 3D design? I don't need anything fancy at all just a simple 3 D rendering.
There are a lot of options for this. I prefer modern OpenGL, but there are probably a ton of libraries out there that would provide the rendering capabilities you need with minimal investment.
> What kind of communication should I use to transfer the sensor data from the COM-GUI to the 3D-renderer?? Windows service?
I'm not sure a Windows service is necessary here unless you want to view the 3D rendering on a separate device or if you need to be "always listening" to the COM port even when the UI is not displayed. I would probably have my 3D rendering stuff in a separate assembly than the COM port stuff, but just call the methods normally without using a service.
Mhm, works fine for me: http://ideone.com/zqcLxz
+/u/CompileBot c++
#include <iostream> #include <string>
using namespace std;
string c; int ant, ban;
int main() { ant = 2; ban = 3; c = (ant > ban) ? "True" : "False"; cout << c; return 0; }
> For speed; if I know that there's no multiple inheritance, and the dynamic_cast succeeded, then it's just persuading the compiler to use the pointer as its original type.
If there's no need for pointer adjustment (no multiple inheritance, or anything of that kind) then static_cast
will produce exactly the same code as reinterpret_cast
, i.e. no code at all. Which means reinterpret_cast
, when it is applicable, does not give you any speed advantage over static_cast
.
However, note that pointer adjustment might become necessary even without multiple inheritance. For example,
struct Base { int i; };
struct Derived : Base { int j; virtual ~Derived() {} };
This hierarchy does not use multiple inheritance. However, upcasts and downcasts between Base *
and Derived *
will adjust the pointer value in a typical implementation (see http://ideone.com/bpnWr7)
If you use reinterpret_cast
for this cast, it will not work properly.
But at bind( callback, target )
, you're not binding to the member function A::method1
. You're binding to the function< void (void) >
function.
Edit it in markdown and put your code between three opening accent marks and close it with three closing accent marks. Check the code and syntax highlighting section here : https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code
You just described the Dvorak layout, which is available to use on all operating systems since at least the mid-90s. It was in Windows starting with 3.1.
If you still want to develop a new keyboard layout, then your question does not pertain here. It needs to be implemented in your operating system, not in C++. In Windows, you need the free MSKLC app from Microsoft website. There are probably similar apps on other OSes.
Good to know, but that was a very weird problem. Generally speaking programs will use the per-user temp directory in C:\Users\<user>\AppData\Local\Temp
.
The windows Temp dir is generally only accessible by privileged apps. Out of interest, check your environment variables (Rapid Environment Editor is a great way to do so). Are there TMP
and TEMP
variables in both the System and User Variables list, or just the System one?
There is: http://curl.haxx.se/libcurl/using/curl-config.html
Based on that, try something like: gcc `curl-config --cflags` ${CFLAGS} -o example example.c `curl-config --libs` ${LDFLAGS}
If you want actual g++, I would recommend installing homebrew, and using that to install gcc/g++ so you get more recent builds.
Actually, you are just going to want brew for pretty much everything CLI anyway.
The version in homebrew is currently:
❯ g++ --version g++-11 (Homebrew GCC 11.1.0_1) 11.1.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I use DosBox to run old DOS games and apps. It works really good in my experience. There's also several frontends available to use with DosBox, such as DOSBox Game Launcher. Just google "DosBox" frontends for more, maybe even better ones.
Well I've managed to link the libraries now and I can run the following code:
// include standard headers
// include GLEW
// include GLFW
int main () { // code return 0; }
however when I try and replace the above with the code from this tutorial http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/ and http://www.glfw.org/documentation.html it won't build. I just copied and pasted everything in both cases just to make sure that everything is working correctly and not only will it not build but it won't give me any error codes.
I don't see the point of this question.
Are you searching for a way to tell your teacher that he goes too slowly for you because you learn things using edabit.com ?
Or am I misunderstanding, most probably ?
Well, this isn't a classic C++ path, but what I did to get up to speed with C++ when coming from years of mostly Python, was to buy one of the recommended texts (I got Accelerated C++) and used that as a reference with Peter Norvig's Design of Computer Programs course (https://www.udacity.com/course/cs212). He teaches that course in Python, but as I went through it, I translated each Python snippet and program into C++. By the time I finished, I knew a lot more about C++ and Python.
int main ()
{
// for loop execution
for( int a = 2; a <= 7; a = a + 1 )
{
std::cout << std::string(a,'>') << std::endl;
}
// 2nd for loop
for( int a = 7; a >= 2; a = a - 1 )
{
std::cout << std::string(a,'<') << std::endl;
}
return 0; }
or something like that.
https://stackoverflow.com/questions/14678948/how-to-repeat-a-char-using-printf my code has some errors because I've been spending too much time in python but that's the general idea.
***changed some things credit /u/PressF1
Still not working as I'm expecting it to but blah, Ill let you figure the rest out.
Do you mean, how can I create a custom floating point data structure of arbitrary size?
I can't help you.
IEEE 754 is the standard for binary floating point. But it's not very easy reading.
Edit : saying that. Boost may help you
You can create a function that returns your skill description. In the header you would just declare it:
#include <string> std::string getSkillDescription(const std::string& skill);
and in the .cpp you define this function:
#include "skill.hpp" std::string getSkillDescription(const std::string& skill) { std::string lc_skill = skill; std::transform(lc_skill.begin(), lc_skill.end(), lc_skill.begin(), std::tolower);
if (lc_skill == "strength" || lc_skill == "1") return "Strength: foo bar.\n\nMore text.\n"; .... }
In your main.cpp you can just include the header and use the function:
#include "skill.hpp"
std::string desc = getSkillDescription("Strength");
Also, instead of converting the string to lower case, you could use boost::iequals for the comparison: http://www.boost.org/doc/libs/1_59_0/doc/html/boost/algorithm/iequals.html
Well, basically it iterates over file entries in path
, and for each entry it checks if its extension is .txt
.
directory_iterator
is an iterator that will return info about all files in given directory (dereferencing it gives us directory_entry
, and incrementing next file in directory).
Just as you can iterate over all characters in string by for (auto &c : some_string)
, by doing for (auto &entry : boost::filesystem::directory_iterator(path))
you iterate over every file in directory.
You can find more info in http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/tutorial.html and http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/reference.html#Class-directory_iterator
To be honest, in 13 years of writing C++ I've never used stream.anything() and always used the inline manipulators such as std::setw(14), together with ostream::sentry (http://www.cplusplus.com/reference/ostream/ostream/sentry/) to clean up the stream state.
Note that for more advanced formatting I usually use Boost.Format (http://www.boost.org/doc/libs/1_57_0/libs/format/doc/format.html) which can be easier and simpler to use for certain types for formatted output.
> What are some good resources?
/r/cpp and /r/cpp_questions are good.
> What IDE is most popular?
Visual Studio Community 2013 possibly.
> Popular frameworks? Designs?
Boost. Otherwise it's all very domain dependant.
> What's the most popular use for C++ now a days?
Define popular? Apps, games, research, art, education.
I guess this is a programming assignment in class, because otherwise you should just use Boost Date Time, or any other library that already does it.
1- boost::interprocess; this is a cross platform library. it is nicely designed. http://www.boost.org/doc/libs/1_55_0/doc/html/interprocess.html
2- for win32, the most simplistic approach would be using mail slots http://msdn.microsoft.com/en-us/library/windows/desktop/aa365576%28v=vs.85%29.aspx
if you are doing very simple stuff, i'm not sure other means of win32 interprocess communication worth your time. boost wraps them all nicely and familiarizing yourself with boost libraries also pays well in long term.
On one level, an iterator is a pointer: fast access into a container, but may become invalid if the container is changed.
On another level, iterators, in general, serve to adapt algorithms to containers, for example, the algorithms in #include <algorithm> work on iterators, so can be applied to many different kinds of containers.
and it doesn't stop there. the Boost Graph Library is an open source collection of algorithms that operate on graph structures, but, because of iterators, allow you to use those algorithms with your graph data structures, making it easy to reuse these tested algorithms to solve your problems (spanning tree, traveling salesman, etc.) without having to touch the tested library source code.
Really good question.
I'd think of a project you'd be really interested in doing first, then learn all the techniques and tools you need to do it. We make music software so my C++ experience is all centred around this: http://www.juce.com - but someone will know what to learn for building game engines if that's what takes your fancy.
You installed one of the versions that's packaged with a compiler, right? For the version that you're using, this would be the appropriate link.
However, that version is also almost 6 years old at this point. Embarcadero recently released an updated version, including GCC 9.2.0 instead of GCC 4.9.2 (and that's ignoring that Dev-C++ hasn't been considered especially good in a long time).
Sublime Text (another decent alternative that's free is notepad++)
I tried to avoid using the IDEs (big software suites that do a lot for you and have many powerful tools) because I didn't want them to become a crutch that would prevent me from being able to successfully write code without them. Once you've got a decent amount of experience and start working on larger projects, they're a huge help for debugging, writing code faster, and managing your projects.
https://www.winpcap.org/devel.htm
Once you have the library and headers installed, point your compiler to them. I don't have any code for c++.
https://www.tcpdump.org/pcap.html is for C. But it should mostly make sense. It wouldn't take much to make it compile in c++.
AFAIR extern C
will still prefix an underscore.
You can use Dependency Walker to view the functions exported from your DLL.
You can link wiht a .def file to assign an exported name different from the internal name.
ld.exe: cannot find -lglew
Well then it looks like you have to find glew! Usually when you are trying to link to an external library, you will use CMake's module system to locate them.
There aren't really that great of courses online. Tbh though, I haven't looked that hard for online courses. I'd grab a c++ programming text book and read through it. Like actually read it. There are some programming problems in most books at all skill levels, but if you need more practice, look into Daily Coding Problem or Lertcode. Both these sites provide easy through advanced level problems that will test your skills.
What I recommend for anyone learning a programming language of any kind is not to use an IDE. Reason being that IDEs do a lot of the work for you (error checking, word completion, etc.) that you may become reliant on. In the future if you get a job that doesn't allow for you to use an IDE, or you are remoted into a system that doesn't have one installed, then you may have to relearn how to program efficiently.
I'm not saying to go learn vim (you can if you want), but just use a normal text editor. On windows I use to use notepad++ and on Linux I use vscode. A lot of people tend to criticize you for your programming text editor of choice, but if it works for you, just go with it.
I'd also recommend learning to compile from the command line using gcc or clang for the same reasons.
Entirely agree with all you said, even that the Kaldi docs are actually one of the better examples. What I don't like is that doxygen seems to shoehorn you into that 90's HTML format. That selector menu on the left is really nothing better than just random collection of links, with not discernible structure to it.
When you look at the doxygen doxygen-generated documentation ( http://www.doxygen.nl ), it's a bit hilarious that the best parts about it are when you don't actually use the doxygen tool but rather just write stuff in markdown.
There is no need to use raw pointers; std::unique_ptr
probably would work fine here. The code would be slightly more verbose, but you won't need to manually free memory. Example
If we are talking about non-Windows platforms I prefer to use XCode on my mac. Here is step-by-step tutor how to create simple console app using XCode http://meandmark.com/blog/2013/11/creating-a-command-line-application-with-xcode/
Also, there are few free IDEs for Linux like Eclipse (with CDT plugin) and Netbeans. Also there is CLion (https://www.jetbrains.com/clion/) which is really powerful, but you should buy a license.
Oh! I can’t believe I didn’t think about this, but since you’re used to Visual Studio, have you looked into Visual Studio for Mac?
I haven’t gotten a chance to check it out, but I’ve heard decent things. I believe you can extend it to work with C++, but I’m not positive.
OK no problem. I know you want to get stuck in and learn C++, but can I make a suggestion? - unless you have a specific project that absolutely requires C++, perhaps you could start by learning C#/Java (depending on if you run Windows or a Mac) first?
There’s a big jump between MATLAB and Java/C#, and an even bigger jump to C/C++.
You’ll find the tools and books with C#/Java more accessible and and you can get started right away.
Both languages will teach you a lot about procedural and object oriented programming, which you can transfer easily into C/C++, but you won’t need to get into gory details of machine architecture straight away.