The idea is fine. The issue is not that clear isn't working, it's that you are printing the vector wrong.
buffer.data() returns a pointer to the data, a char* in other words. When you use std::cout on a char* it expects a nul terminated string (i.e. C style string), but you aren't giving it that as there is no nul character in your data, so you get unpredictable results.
Here's some code that prints the vector in the correct way (using std::copy and std::ostreambuf_iterator)
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
int main()
{
std::vector<char> buffer;
buffer.push_back('2');
buffer.push_back('5');
buffer.push_back('6');
std::copy(buffer.begin(), buffer.end(), std::ostreambuf_iterator(std::cout));
std::cout << std::endl;
buffer.clear();
buffer.push_back('3');
std::copy(buffer.begin(), buffer.end(), std::ostreambuf_iterator(std::cout));
std::cout << std::endl;
return 0;
}