Thread: Cannot push_back string at the end of vector

  1. #1
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Still in the egg

    Cannot push_back string at the end of vector


    I have below classes
    class moClassValueContainer {
    	string	name;
    	int		maxNodeCount;
    	vector<string> headerFields;
    typedef enum {SINGLE,LIST} valueType; // this is C style
    class Container {
    		Container (xml_node n);
    		valueType getType() { return type; }       
    		vector< vector<string> > getListNames();    
    		vector< vector<string> > getListValues();   
    		string getListElement(string n);		
    		string getName();                          
    		string getValue();                         
    		int getElementCount();                     
    		valueType type;
    		xml_node node;
    		int count;      // for list only, otherwise count = 0
    		int itemNo;
    		string name;
    		string moClass;
    		vector< vector<string> > listNames;
    		vector< vector<string> > listValues;
    		void analyseList();
    		bool listAnalyzed;
    Container::Container(xml_node n) {
    	node = n;
    	itemNo = 0;
    	listAnalyzed = false;
    	name = string(node.attribute("name").value());
    	if (!string("list")) {
    		type = LIST;
                    count = 0;
    	 } else {
    		type = SINGLE;
    		count = 1;
    string Container::getName() {
    	if (type == SINGLE)
    		return name;
    		return "";
    In my main.cpp, I have blow loop
    for (xml_node tnode = it->first_child(); tnode ; tnode = tnode.next_sibling()) {
            Container tmpContainer(tnode);
    	if (tmpContainer.getType() == SINGLE) {
                    string t = tmpContainer.getName();
           } else {
    I cannot push_back(t). I examined the code with debugger, t has correct string value assigned, but even after 20-30 iterations, there is no element for headerFields vector. What is wrong here?

    Thanks in advance...

  2. #2
    Registered User
    Join Date
    Jun 2005
    The probability of anyone being able to help you based on information you have provided is vanishingly small.

    Try providing a small and complete example of actual code (i.e. something that can be compiled, linked, and run to reproduce your problem). That doesn't mean post all of your code. It means eliminate parts of the code until you get a small sample that produces the same symptoms. In the process of producing such a small sample, you might have an "Aha!" moment. If not, other people will have more chance of being able to help.

    You've cut out things you presumably deem irrelevant, but are potentially a contributor to your symptoms. There is a rule of thumb: if you don't know what the problem is, you'll probably be wrong in deciding what is relevant.

    You probably need to read this as well
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector push_back array
    By Tropod in forum C++ Programming
    Replies: 3
    Last Post: 10-15-2010, 04:46 PM
  2. Weird STL vector push_back problrms
    By creativeinspira in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2007, 04:30 PM
  3. Error from vector push_back()
    By The Wazaa in forum C++ Programming
    Replies: 7
    Last Post: 03-11-2006, 01:15 PM
  4. vector.push_back(anotherVector)
    By boojus in forum C++ Programming
    Replies: 2
    Last Post: 11-22-2003, 05:07 PM
  5. vector<bool> push_back
    By ygfperson in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2003, 08:48 PM