Created
April 21, 2010 12:41
-
-
Save masaki/373769 to your computer and use it in GitHub Desktop.
C++ stringstream buffer sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <vector> | |
typedef std::vector<char> Buffer; | |
void assign(std::stringstream& stream) { | |
Buffer buffer; | |
buffer.push_back('M'); | |
buffer.push_back('A'); | |
buffer.push_back('S'); | |
buffer.push_back('A'); | |
buffer.push_back('K'); | |
buffer.push_back('I'); | |
stream.str(""); | |
stream.clear(); | |
stream.write(&buffer.at(0), buffer.size()); | |
} | |
int main(int argc, char* argv[]) { | |
std::stringstream stream("masaki"); | |
std::cout << stream.str() << std::endl; | |
assign(stream); | |
std::cout << stream.str() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment