strstream


1. Redirecting Standard Output

#include <iostream>
#include <sstream>

int main() {
    std::stringstream buffer;
    std::streambuf* old_buffer = std::cout.rdbuf(buffer.rdbuf());
    std::cout << "Hello, world!" << std::endl;
    std::string output = buffer.str();
    std::cout.rdbuf(old_buffer);
    std::cout << output;
    return 0;
}

2. String Formatting

#include <sstream>
#include <iomanip>

int main() {
    std::stringstream ss;
    ss << std::setw(10) << std::left << "Hello" << std::setw(10) << std::left << "World";
    std::string formatted_string = ss.str();
}

3. Tokenization

4. Input Buffering

5. CSV Parsing

6. XML Parsing

7. HTML Parsing

8. Converting Numbers to Strings

9. Converting Strings to Numbers

10. Manipulating Strings

11. Joining Strings

12. Splitting Strings

13. Inserting and Removing Characters

14. Logging Messages

15. Serializing Objects

16. Generating Random Strings

17. Hashing Strings

18. Encrypting Strings

19. Decoding Strings

20. Obfuscating Strings

21. Compressing Strings

22. Timestamping Strings

23. Generating Unique IDs

24. Converting Strings to Integers

25. Converting Integers to Strings

26. Converting Floating-Point Numbers to Strings