Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
Z

Zac Howland

@Zac Howland
About
Posts
1.5k
Topics
13
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • inputing string & int from file to array.
    Z Zac Howland

    Putting the grades in a stringstream prevents the istream from trying to read the rest of the file. When the istream gets to the end of the file (that is, when the >> returns an eof()) it doesn't add anything to the vector (which is what you were seeing).

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    C / C++ / MFC data-structures question

  • inputing string & int from file to array.
    Z Zac Howland

    Here is a working example with the data format you gave:

    #include <string>
    #include <vector>
    #include <algorithm>
    #include <iterator>
    #include <iostream>
    #include <fstream>
    #include <sstream>
    
    using namespace std;
    
    class Student
    {
    public:
    	Student() : _Name("") {}
    	~Student() {}
    
    	void setName(const string& name) { _Name = name; }
    	string getName() const { return _Name; }
    
    	void setGrades(const vector& grades) { _Grades.assign(grades.begin(), grades.end()); }
    	vector getGrades() const { return _Grades; }
    private:
    	string _Name;
    	vector _Grades;
    };
    
    std::ostream& operator<<(std::ostream& os, const Student& s)
    {
    	os << s.getName() << " ";	// NOTE:  older versions of STL will require a character buffer instead
    	const vector grades = s.getGrades();
    	copy(grades.begin(), grades.end(), ostream_iterator(os, " "));
    	os << std::endl;
    	return os;
    }
    
    std::istream& operator>>(std::istream& is, Student& s)
    {
    	string name = "";	// NOTE:  older versions of STL will require a character buffer instead
    	is >> name;
    	string sGrades = "";
    	getline(is, sGrades);
    	vector grades;
    	stringstream ss(sGrades);
    	copy(istream_iterator(ss), istream_iterator(), back_inserter(grades));
    	s.setName(name);
    	s.setGrades(grades);
    	return is;
    }
    
    int main()
    {
    	ifstream fin;
    	vector students;
    	fin.open("data.txt");
    	copy(istream_iterator(fin), istream_iterator(), back_inserter(students));
    	fin.close();
    	// do whatever you want with students vector
    
    
    	std::copy(students.begin(), students.end(), ostream_iterator(cout, "\n\n"));
    }
    

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    C / C++ / MFC data-structures question

  • inputing string & int from file to array.
    Z Zac Howland

    It should be getting 1 student only (due to the previously mentioned bug in that example). Fixing the bug will allow it to copy all the students in the file to the vector. The easiest way to do this without having to modify the data file format is to modify the input stream extractor to get the id and then calling getline to store the rest of the line as a string. Then create a stringstream object and extract the grades (everything in the streamstream) into the grades vector using a copy operation. Basically, you add 2 lines of code and change the iterators for the grades-copy call.

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    C / C++ / MFC data-structures question

  • Reading from File question... [modified]
    Z Zac Howland

    No problem. I figured as much ;) It wouldn't take much to get that to be working code, but originally it was just meant as a nudge in the right direction.

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    C / C++ / MFC question c++ ios data-structures help

  • Reading from File question... [modified]
    Z Zac Howland

    Looking back at it, is a slight bug in my example code. Basically, since the id's and grades are both longs, there is no way to tell them apart. It would probably be helpful to modify the output slightly by putting a grade count in between the student id and the first grade so that you can modify the copy call (for obtaining the grades) to just grab that many items (instead of grabbing everything that is left in the file). Another (possibly simpler alternative) would be to grab the student id, and then use getline to obtain the rest of the line, place that string into a stringstream and then call copy on it (this solution has the added benefit of not having to change the input/output file format).

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    C / C++ / MFC question c++ ios data-structures help

  • Declaration of CSemaphore fails
    Z Zac Howland

    BuckBrown wrote:

    class CTests : public CWnd { // Construction public: CTests(); CTemperature* pTemperature; COutput* pOutput; CGPIB* pGPIB; CTabPageSSL* pTabPage; CSemaphore cph(1, 5);

    Doing that in the header file won't compile. The overloaded constructor should be invoked using the constructor of your CTests class:

    CTests::CTests() : cph(1, 5) { // do whatever else you want to in the constructor here }
    

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    C / C++ / MFC c++ help tutorial question

  • Yeah, i know i said i was leaving...
    Z Zac Howland

    Red Stateler wrote:

    This event is going to spark an FBI-Mounty alliance. All of mankind is doomed.

    Great ... lets put 2 incompetent agencies on the job ;P

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room

  • Yeah, i know i said i was leaving...
    Z Zac Howland

    Red Stateler wrote:

    It should be a crime to waste the FBI's time on trivial and innocuous acts when they have much more important things to do.

    I missed whatever started this mess ... but I'm curious why the FBI would even be considered to be involved in something like this. Last time I checked, CP was run on servers in Canada ... has that changed?

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room

  • Torture: not just for muslims anymore
    Z Zac Howland

    Diego Moita wrote:

    Wasn't the article referring to Chicago?

    Exactly ;P You obviously have never been to Chicago :laugh:

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room html com question

  • Real Estate Question
    Z Zac Howland

    It is basically a townhouse that is only attached on 1 side. There is a whole development that is built like that not too far from where I live now. They are kind of neat.

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room java question

  • Real Estate Question
    Z Zac Howland

    Do you have any trouble keeping them occupied? Just thinking down the road, I'd probably want to rent it out at some point in time when I'm ready to buy a bigger house.

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room java question

  • Real Estate Question
    Z Zac Howland

    Since this morning is slow in the SB ... I'm looking into buying a condo or house this coming spring. The one I'm most interested in is a duplex-style townhouse. I'm curious if anyone has lived in one of thsoe and what the experience was like (trouble with neighbors, difficulty doing things around the house/common property, difficulty reselling, etc).

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room java question

  • Torture: not just for muslims anymore
    Z Zac Howland

    Diego Moita wrote:

    Like you'd care anything about freedom and rule of the law.

    Not to be nit-picky here, but these actions are happening in a war zone. Ever heard the saying, "All is fair in love and war"? The article talks about American rule of law, however, it fails to realize that in a war zone outside of US soil, there is no such law. The only law that these soldiers have is the code of military justice. What the article truly fails at is understanding the words "war" and "soldier".

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room html com question

  • duplicated member variables in derived classes
    Z Zac Howland

    jhwurmbach wrote:

    Out of dire need when the MS-C++ was so fundamentally broken as being incapable of compiling any STL.

    It was created because there was no STL at the time. STL wasn't standard until 1999, MFC's collection classes have been around since 1994.

    jhwurmbach wrote:

    There is no need to use the afxtempl.h-collections in new software!

    There is nothing fundamentally wrong with MFC's collection classes. They are perfectly fine, and unless you are actually making use of some of the more advanced features of STL, MFC's templates are even easier to use in some cases. You use the tool that fits you best for what you need to accomplish. To the OP, the biggest problem with the code is the member variables in the derived classes hiding the one in the base class. A better way to do this kind of thing is:

    class A
    {
    public:
    	A(int type) : _Type(type) {}
    	virtual ~A() {}
    
    	virtual int getType() = 0;
    };
    
    class B : public A
    {
    public:
    	B() {}
    	virtual ~B() {}
    
    	virtual int getType() { return TYPEB; }
    };
    
    class C : public A
    {
    public:
    	C() {}
    	virtual ~C() {}
    
    	virtual int getType() { return TYPEC; }
    };
    

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    Clever Code c++ debugging help question

  • Goldman CEO's $53.4M Bonus Breaks Record
    Z Zac Howland

    PaulC1972 wrote:

    Not necessarily true. When I worked at Target about 13 years ago, when beginning college, the majority of people working there were 30-40-50 year olds holding down several minimum wage jobs just to make ends meet.

    Not to sound cold, but it isn't the government's job to be the safety net for people who either can't, or refuse to pay their dues when they are younger (e.g. get an education or obtain basic skills to help them get and keep a steady job). I use to work at Food Lion as a CSM (first couple years of college). I had a few people that worked for me that were doing it as a career (most of the employees were either teenagers/college students or people with full time jobs doing it for extra cash). The ones using it as a career were those that dropped out of school, partied through their 20's, and wondered why they weren't making any money in their 30's. The minimum wage was never designed to give the entire population a baseline off of which they could live (and it will never accomplish that either -- basic economics will tell you that). It was designed to keep companies from exploiting workers by paying them pennies a day and charging a fortune for the products they produce. In many ways, it is both antiquated and unneccessary in today's society.

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room csharp java html database com

  • Holiday gift suggestion ...
    Z Zac Howland

    Pete O`Hanlon wrote:

    One thing though - no lingerie.

    See, there actually is some nice lingerie she wants (the Christmas outfit that Heidi Klume is wearing in the new VS commercials) ... but it is way too soon to a) get her something THAT personal ... and b) something that expensive (at least for a single item). Which is also why I'm avoiding the iPod I know she wants ...

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room question discussion

  • Holiday gift suggestion ...
    Z Zac Howland

    Red Stateler wrote:

    She started it.

    (Switching over to Dad's role here) I don't care who started it ... if you don't stop, I'll ground you both ;P

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room question discussion

  • Holiday gift suggestion ...
    Z Zac Howland

    Tim Craig wrote:

    Well, you did pick the SB rather than the Lounge. Or were you looking for spicy gift suggestions?

    That was just out of habit ... could have been put in the Lounge easy enough.

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room question discussion

  • Holiday gift suggestion ...
    Z Zac Howland

    Red Stateler wrote:

    I'll fetch my mother-in-law on you. You won't have a chance.

    Okay children ... back to your neutral corners or I will have to send you to your rooms! :sigh:

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room question discussion

  • Holiday gift suggestion ...
    Z Zac Howland

    Red Stateler wrote:

    $50!!?!?! Are you kidding me??? You could eat at McDonald's for a small fraction of that!

    Only if I never wanted her to agree to go out with me again ;P

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    The Back Room question discussion
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups