|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On May 10 2014 08:40 Nesserev wrote:Show nested quote +On May 10 2014 08:21 Ottoxlol wrote: Have been googling and thinking for a couple of hours I can't crack whats wrong with my program. Would make my day if someone could help. Its a simple inventory system where I have to use heterogeneous collection, dynamic memory allocation and classes in C++. I am finished if not for the Save() function that I would use to write my objects out to a file the same way I read them.
For the parent I use: virtual void Save(fstream &file) {file << thingsformattedinawayineedthem; } ,
for the children: void Save(fstream &file){file << 'x' ; Camera::Save(file); file << otherthingsformattedinawayineedthem; }
the function that calls for every object to save itself is: void Saveall(vector<Parent*> inventory,fstream &file){for (unsigned i=0; i<inventory.size(); i++){inventory[i]->Save(file);}
I did almost exactly the same for a Listall function that prints every objects variables and it worked so I think it has to do something with the way I handle the fstream(currently it does nothing to the file) Bonus question: is there a clear command for files? if not is there an elegant solution to clearing it(txt in this case). Well, your explanation isn't very clear to begin with, what's the problem that you have? EDIT: For your bonus question, when you open a file, it's cleared from all its contents implicitly (unless you tell it to do otherwise). You can choose the mode in which you open it, by adding the right bitflags, like app to append to the file: http://www.cplusplus.com/reference/fstream/fstream/open/ // fstream::open / fstream::close #include <fstream> // std::fstream
int main () {
std::fstream fs; fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);
fs << " more lorem ipsum";
fs.close();
return 0; }
Doesn't C++ have a function that can save and restore an object? I know that most languages support a function that for example saves all of the global variables used by an object as a mapping and then you get the restore function to assign values stored in the file to this variable (kinda JSON like I guess).
I'm genuinely interested in this
|
On May 10 2014 09:52 Manit0u wrote:Show nested quote +On May 10 2014 08:40 Nesserev wrote:On May 10 2014 08:21 Ottoxlol wrote: Have been googling and thinking for a couple of hours I can't crack whats wrong with my program. Would make my day if someone could help. Its a simple inventory system where I have to use heterogeneous collection, dynamic memory allocation and classes in C++. I am finished if not for the Save() function that I would use to write my objects out to a file the same way I read them.
For the parent I use: virtual void Save(fstream &file) {file << thingsformattedinawayineedthem; } ,
for the children: void Save(fstream &file){file << 'x' ; Camera::Save(file); file << otherthingsformattedinawayineedthem; }
the function that calls for every object to save itself is: void Saveall(vector<Parent*> inventory,fstream &file){for (unsigned i=0; i<inventory.size(); i++){inventory[i]->Save(file);}
I did almost exactly the same for a Listall function that prints every objects variables and it worked so I think it has to do something with the way I handle the fstream(currently it does nothing to the file) Bonus question: is there a clear command for files? if not is there an elegant solution to clearing it(txt in this case). Well, your explanation isn't very clear to begin with, what's the problem that you have? EDIT: For your bonus question, when you open a file, it's cleared from all its contents implicitly (unless you tell it to do otherwise). You can choose the mode in which you open it, by adding the right bitflags, like app to append to the file: http://www.cplusplus.com/reference/fstream/fstream/open/ // fstream::open / fstream::close #include <fstream> // std::fstream
int main () {
std::fstream fs; fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);
fs << " more lorem ipsum";
fs.close();
return 0; }
Doesn't C++ have a function that can save and restore an object? I know that most languages support a function that for example saves all of the global variables used by an object as a mapping and then you get the restore function to assign values stored in the file to this variable (kinda JSON like I guess). I'm genuinely interested in this 
Not built in - there's boost::serialization which by all accounts is pretty nice though, otherwise mostly you're on your own
|
On May 09 2014 19:24 Nesserev wrote:Show nested quote +On May 09 2014 10:24 Blisse wrote:On May 08 2014 16:25 phar wrote: Can you provide a bit more detail? Do you mean supporting multiple ways of logging into the same service? Not supporting it, but what to do when you do have a user using multiple services and you want to combine them all into one person. Do you just treat all the different log-ins as different people? Then that means if that one person logs in to multiple accounts/services to do something, does the person appear as the same person or as different people? You should probably use a Single Sign-on Authentication system, like google does.
Uh, I'm actually talking about merging multiple identities into one rather than a signing identity. More of a way of resolving the issue of people signing in using different identities, and into a single person.
|
Ahh I see what you're talking about now.
I've seen it both ways. I've seen systems that treat all separate ways of login as separate users. I've seen systems that try to merge them together into a single user, so you can use any of the login ways.
I must say as an end user I prefer the latter. On a new login type, you prompt for auth credentials of an existing login (redo oath from the original login if the third party supports that, or whatever), and merge that way. Though I have no idea how they treat revoking single logins vs whole account, how to detect if someone's lost access to one of their three login methods but not the other two, etc. I can imagine it'd be more of a headache.
|
On May 10 2014 08:40 Nesserev wrote:Show nested quote +On May 10 2014 08:21 Ottoxlol wrote: Have been googling and thinking for a couple of hours I can't crack whats wrong with my program. Would make my day if someone could help. Its a simple inventory system where I have to use heterogeneous collection, dynamic memory allocation and classes in C++. I am finished if not for the Save() function that I would use to write my objects out to a file the same way I read them.
For the parent I use: virtual void Save(fstream &file) {file << thingsformattedinawayineedthem; } ,
for the children: void Save(fstream &file){file << 'x' ; Camera::Save(file); file << otherthingsformattedinawayineedthem; }
the function that calls for every object to save itself is: void Saveall(vector<Parent*> inventory,fstream &file){for (unsigned i=0; i<inventory.size(); i++){inventory[i]->Save(file);}
I did almost exactly the same for a Listall function that prints every objects variables and it worked so I think it has to do something with the way I handle the fstream(currently it does nothing to the file) Bonus question: is there a clear command for files? if not is there an elegant solution to clearing it(txt in this case). Well, your explanation isn't very clear to begin with, what's the problem that you have? EDIT: For your bonus question, when you open a file, it's cleared from all its contents implicitly (unless you tell it to do otherwise). You can choose the mode in which you open it, by adding the right bitflags, like app to append to the file: http://www.cplusplus.com/reference/fstream/fstream/open/ // fstream::open / fstream::close #include <fstream> // std::fstream
int main () {
std::fstream fs; fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);
fs << " more lorem ipsum";
fs.close();
return 0; }
Yeah, this is how I use it but it doesn't work, thats why I asked if someone sees where could be the problem
|
On May 10 2014 16:34 Ottoxlol wrote:Show nested quote +On May 10 2014 08:40 Nesserev wrote:On May 10 2014 08:21 Ottoxlol wrote: Have been googling and thinking for a couple of hours I can't crack whats wrong with my program. Would make my day if someone could help. Its a simple inventory system where I have to use heterogeneous collection, dynamic memory allocation and classes in C++. I am finished if not for the Save() function that I would use to write my objects out to a file the same way I read them.
For the parent I use: virtual void Save(fstream &file) {file << thingsformattedinawayineedthem; } ,
for the children: void Save(fstream &file){file << 'x' ; Camera::Save(file); file << otherthingsformattedinawayineedthem; }
the function that calls for every object to save itself is: void Saveall(vector<Parent*> inventory,fstream &file){for (unsigned i=0; i<inventory.size(); i++){inventory[i]->Save(file);}
I did almost exactly the same for a Listall function that prints every objects variables and it worked so I think it has to do something with the way I handle the fstream(currently it does nothing to the file) Bonus question: is there a clear command for files? if not is there an elegant solution to clearing it(txt in this case). Well, your explanation isn't very clear to begin with, what's the problem that you have? EDIT: For your bonus question, when you open a file, it's cleared from all its contents implicitly (unless you tell it to do otherwise). You can choose the mode in which you open it, by adding the right bitflags, like app to append to the file: http://www.cplusplus.com/reference/fstream/fstream/open/ // fstream::open / fstream::close #include <fstream> // std::fstream
int main () {
std::fstream fs; fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);
fs << " more lorem ipsum";
fs.close();
return 0; }
Yeah, this is how I use it but it doesn't work, thats why I asked if someone sees where could be the problem
So this is where you post your code, so that we have a chance to help. Instead of just writing what's wrong.
|
well I did post the relevant code, I figured it out anyway, I used fstream instead of using i/o separately probably that's what it didn't like, I divided it and now it works. thanks for the help big programmers
|
On May 10 2014 18:23 Ottoxlol wrote:well I did post the relevant code, I figured it out anyway, I used fstream instead of using i/o separately probably that's what it didn't like, I divided it and now it works. thanks for the help big programmers 
Arrrghh!!! This isn't only aimed directly at you -- that's like the number one quote in this thread that bothers me, "I posted the the relevant code", "here's the relevant section"...
If one can't figure something out, how does one assume that they know what the relevant piece of code is? Isn't that decision actually up to the person who fixes that problem?
/rant
|
|
|
Could any of you suggest some learning material for embedded software development in ANSI C? You know, stuff like best practices for creating drivers and programming for devices running with 16K flash, 4K RAM and 8MHz CPU...
|
Hi guys, i'm about to enrol into university for a computer science degree and i have been interested in programming for a really long time. However, i'm just baffled at where to start cause there are just too many languages to learn. I read the OP but there isn't much C learning resources out there(I think?) so I want to try at least picking up C++ or C# first.
Is there any beginning knowledge that I should learn before starting on any language and is there any language that are better for beginners such as me to learn? Thanks very much!
|
On May 11 2014 01:12 Invictus wrote: Hi guys, i'm about to enrol into university for a computer science degree and i have been interested in programming for a really long time. However, i'm just baffled at where to start cause there are just too many languages to learn. I read the OP but there isn't much C learning resources out there(I think?) so I want to try at least picking up C++ or C# first.
Is there any beginning knowledge that I should learn before starting on any language and is there any language that are better for beginners such as me to learn? Thanks very much! There should be plenty of resources for C. But neither C nor C++ are particularly great for beginners, at least imo. There's the argument that these languages teach you valuable things about the low level part of programming, but honestly, programming is all about abstraction. You'll be fine if you start with a more beginner-friedly language (like C# or Java; Python might be a good idea too but I don't know it well enough to recommend it) and just assume that the low level stuff works as it should.
|
|
|
Linux is nice and all, certainly worth exploring. But you should learn one thing at a time. That also happens to be an important mindset in programming: Tackle your problems one by one.
|
Check your university's cs department. You can probably access the courses of earlier years and see what they use. Remember to not only look at the 1st semester stuff, since they often use special/stupid stuff.
|
On May 11 2014 01:51 Nesserev wrote:Show nested quote +On May 11 2014 01:12 Invictus wrote: Hi guys, i'm about to enrol into university for a computer science degree and i have been interested in programming for a really long time. However, i'm just baffled at where to start cause there are just too many languages to learn. I read the OP but there isn't much C learning resources out there(I think?) so I want to try at least picking up C++ or C# first.
Is there any beginning knowledge that I should learn before starting on any language and is there any language that are better for beginners such as me to learn? Thanks very much! I'd recommend picking up Python as your first language instead of C++ or C#. Python is a great language, with a clean and simple look, a lot of support, but it's also as beginner friendly as it gets: - you install python - you write a script (which you can write in notepad) - you execute the script with python At our university, they use 'How to think like a computer scientist' to teach all the basics of programming in around 4-5 weeks, which is an 'open' free book that you can download in many places. It's a great introduction to all the core concepts of (imperative/object oriented) programming languages, and also introduces you to some important data structures. You shouldn't be afraid of there being so many programming languages; All the differences basically come down to styles and a couple of features. I assume you use windows; I recommend that you learn how to use the commandline and to get a virtual linux machine running to dip in the wonders of linux (if you haven't yet), and have some fun with that.
I think it depends on what you really do with Windows and there are basically 3 options here: 1. Do you play a lot of games? Dual-boot. (Note: we're talking latest AAA titles here for the most part, you can run most games via WINE in Linux and often they even work better than in Windows - Civilization IV & V would be an example of such a case) 2. Do you develop in .NET or otherwise need native Windows stuff (your employer requires MS Office for example)? Dual-boot. 3. Any other case? Get rid of Windows because apart from the above it's a useless piece of crap.
People are really too afraid of Linux. Migration might've been hard in the past but this days Linux is I think even more user-friendly than Windows. I've purged my wife's laptop of Windows (she's not very computer savvy) and installed Linux there some years ago, now she's extremely frustrated when she has to do anything on a computer with Windows and she got used to Linux in no more than a couple of days.
For starters you can either go newbie-friendly with Linux by picking a distro that has plenty of wizards and is popular (thus a lot of "how do I do xxx in dist yyy?" on the web) like Ubuntu, Crunchbang (for those who like minimalism), openSUSE or go anti-newbie but learn Linux inside-out by picking a distro where you get a very basic setup and have to do everything manually, including kernel recompilation. In the latter case it's important to pick a distro that's very well documented like Arch or Gentoo (Arch is easier since it uses a package manager so you don't have to compile from source).
I don't think VM is an option for anything past CLI programming since it can get incredibly slow and frustrating.
|
On May 11 2014 02:07 Manit0u wrote: I think it depends on what you really do with Windows and there are basically 3 options here: 1. Do you play a lot of games? Dual-boot. (Note: we're talking latest AAA titles here for the most part, you can run most games via WINE in Linux and often they even work better than in Windows - Civilization IV & V would be an example of such a case) 2. Do you develop in .NET or otherwise need native Windows stuff (your employer requires MS Office for example)? Dual-boot. 3. Any other case? Get rid of Windows because apart from the above it's a useless piece of crap.
So if you don't need Windows, don't use Windows? Obvious statement is obvious 
Also, I never understood all the hate for Windows. Since Win 2k it's been a fine OS that just works.
On May 11 2014 02:07 Manit0u wrote: For starters you can either go newbie-friendly with Linux by picking a distro that has plenty of wizards and is popular (thus a lot of "how do I do xxx in dist yyy?" on the web) like Ubuntu, Crunchbang (for those who like minimalism), openSUSE or go anti-newbie but learn Linux inside-out by picking a distro where you get a very basic setup and have to do everything manually, including kernel recompilation. In the latter case it's important to pick a distro that's very well documented like Arch or Gentoo (Arch is easier since it uses a package manager so you don't have to compile from source).
So you can use a lot of wizards like in Windows? ;o) Or you can go all hardcore and do it yourself... Like you can in Windows ;o) Or you can compile from sources, which for practical reasons serves no purpose, but is nice to learn how linux actually works. That you can't do on Windows, I'll give you that.
On May 11 2014 02:07 Manit0u wrote: I don't think VM is an option for anything past CLI programming since it can get incredibly slow and frustrating.
Get a new i5 or i7 and VMWare Player - speed is so close to native you won't notice the difference anyway.
Instead of religious war which is quite normal in this business, be pragmatic. Pick the right tool for the right job. Learn new paradigms and ideas, and apply them where appropriate. That's what separates the good from the great.
|
Do you guys use Java reflection? Or is this only a Java EE thing?
|
On May 11 2014 02:50 bangsholt wrote:Show nested quote +On May 11 2014 02:07 Manit0u wrote: I think it depends on what you really do with Windows and there are basically 3 options here: 1. Do you play a lot of games? Dual-boot. (Note: we're talking latest AAA titles here for the most part, you can run most games via WINE in Linux and often they even work better than in Windows - Civilization IV & V would be an example of such a case) 2. Do you develop in .NET or otherwise need native Windows stuff (your employer requires MS Office for example)? Dual-boot. 3. Any other case? Get rid of Windows because apart from the above it's a useless piece of crap. So if you don't need Windows, don't use Windows? Obvious statement is obvious  Also, I never understood all the hate for Windows. Since Win 2k it's been a fine OS that just works. Show nested quote +On May 11 2014 02:07 Manit0u wrote: For starters you can either go newbie-friendly with Linux by picking a distro that has plenty of wizards and is popular (thus a lot of "how do I do xxx in dist yyy?" on the web) like Ubuntu, Crunchbang (for those who like minimalism), openSUSE or go anti-newbie but learn Linux inside-out by picking a distro where you get a very basic setup and have to do everything manually, including kernel recompilation. In the latter case it's important to pick a distro that's very well documented like Arch or Gentoo (Arch is easier since it uses a package manager so you don't have to compile from source). So you can use a lot of wizards like in Windows? ;o) Or you can go all hardcore and do it yourself... Like you can in Windows ;o) Or you can compile from sources, which for practical reasons serves no purpose, but is nice to learn how linux actually works. That you can't do on Windows, I'll give you that. Show nested quote +On May 11 2014 02:07 Manit0u wrote: I don't think VM is an option for anything past CLI programming since it can get incredibly slow and frustrating. Get a new i5 or i7 and VMWare Player - speed is so close to native you won't notice the difference anyway. Instead of religious war which is quite normal in this business, be pragmatic. Pick the right tool for the right job. Learn new paradigms and ideas, and apply them where appropriate. That's what separates the good from the great.
Ad.1 - Most people don't even realize that you may "not need" Windows, that was my point there. And it's not a fine OS that "just works"... Out of the box you can't do that much with it, unlike Linux, where you get a full office suite, image processing and editing software, a selection of web browsers that don't suck and media players that are actually good.
Ad. 2 - I mentioned the wizards because that's what people migrating from Windows might be more comfortable with as it makes the entire experience more familiar. Only later, when you're better acquainted with Linux do you forsake most, if not all, wizards for console (in my current setup I don't even have the desktop or much of a GUI, I do almost everything from console this days).
And as far as right tools for the job go, unless you're going to do Windows-specific development I see no reason sticking with Windows. Even though you can use VM having it native would still be preferable and if you're going to be spending 8-10 hours a day in this environment you might as well make it your primary and get comfortable with it.
|
wow thanks for all the advice! so i think i shall start on python instead then.
on a side note, is Linux really that good? everyone seems to be recommending it as the to go platform. And yes i'm using windows.
|
|
|
|
|
|