standard-library

Getting Spaces to Play Nicely with C++ Input Streams

First consider this sample C++ code: std::string input1, input2, input3; std::cout << "Enter Input 1: "; std::cin >> input1; std::cout << std::endl << "Enter Input 2: "; std::cin >> input2; std::cout << std::endl << "Enter Input 3: "; std::cin >> input3; If for input1 I enter something like "Good day neighbors" then input1 is set to "...

Any reason why an std::ofstream object won't close properly?

I noticed in my C++ code that anytime I close an std::ofstream object I'm unable to reopen the file I closed with std::ifstream. std::ifstream's open function will always fail. Is there anything 'extra' I can do to ensure that my std::ofstream object closes properly? Someone's probably going to ask to see my specific code so for the sa...

How does stringstream work internally?

I'm asking in context of performance. Is stringstream simply a string/vector, so writing to it may result in its whole content being copied to a bigger chunk of memory, or is it done in a more tricky way (say, a list of strings or whatever)? ...