How to store by value instead of reference

Right now I am reading a XML file into a char pointer array, and storing the value in that array into a stack. I'm reading every line into the same char pointer array so when I delete it and replace it, all of the values in the stack get changed to the new value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
*while(!pfile.eof())
	{
		pfile.get(c);

		while (c != '\n' && !pfile.eof())
		{		
			buffer[inc++] = c;
			pfile.get(c);	
				
		}
                 
                tags.push(buffer); // everything in this will change to the new values
                memset(buffer, 0, sizeof (buffer));
        }



Question: How can I store each line read by my program so that the values don't change when I empty the char pointer array, and replace it with the new line?
Last edited on
What is the "tags"?

Why don't you std::getline into std::string?
buffer is a char pointer, I guess I can try that but wont I have the same problem with it storing the address of the string and not the value that it holds?
I did not ask about the buffer. I did ask the (exact) type of tags.
Oh sorry, tags is a stack of type char*.
A std::stack<char*>? Could you use std::stack<std::string> instead?
Topic archived. No new replies allowed.