sstream


1. Reading and Writing to a String Stream:

#include <sstream>
std::stringstream ss;
std::string str = "Hello World";

// Write to the stream
ss << str;

// Read from the stream
std::string read_str;
ss >> read_str;

// Check if the read string matches the original string
if (read_str == str)
  std::cout << "Strings match!\n";

2. Formatting Output:

#include <sstream>
using namespace std;

ostringstream mystream;

// Format and write float with precision of 2 decimal places
mystream << std::fixed << std::setprecision(2) << 3.14159;

// Retrieve the formatted string
string formatted_str = mystream.str();

3. Parsing Input:

4. Converting Numbers to Strings:

5. Tokenizing a String:

6. Converting String to Lowercase/Uppercase:

7. Splitting a String by Delimiter:

8. Reading from a File into a String Stream:

9. Writing to a File from a String Stream:

10. Using String Stream for Debugging:

11. Creating a CSV File:

12. Parsing XML Using String Stream:

13. Converting a Map to a String:

14. Converting a Vector to a String:

15. Creating a JSON String from an Object:

16. Parsing JSON String into an Object:

17. Creating a Custom String Delimiter:

18. Parsing a Fixed-Width File:

19. Reading a Delimited File into a Vector of Vectors:

20. Calculating Statistics from a Data File:

21. Creating a Report from a Structured Log File:

22. Parsing a URL:

23. Generating Random Data:

24. Encrypting and Decrypting a String:

25. Counting Occurrences of a Character in a String:

26. Creating a CSV File with Header:

27. Serializing a Custom Object to a String:

28. Deserializing a Custom Object from a String:

29. Tokenizing a String with Custom Delimiters:

30. Counting the Number of Lines in a String:

31. Creating a Histogram from a Data File:

32. Parsing a Log File for Errors:

33. Creating a Markdown Document from HTML:

34. Parsing a Command-Line Interface (CLI) Argument:

35. Creating a JSON Patch from an Object:

36. Removing Duplicate Lines from a Text File:

37. Generating a Random Password:

38. Creating a Color Palette from a Hex Code:

39. Parsing and Converting Numbers from a String:

40. Creating a CSV File with Headers and Line Breaks:

41. Creating a Tab-Separated File:

42. Converting a String to UPPERCASE:

43. Converting a String to LOWERCASE:

44. Generating a Random Number:

45. Calculating the Sum of Numbers from a String:

46. Extracting Words from a String:

47. Converting an Integer to a String:

48. Reversing a String:

49. Combining Multiple Strings into One:

50. Splitting a String Based on a Delimiter: