SStream, String, Integer, And Recursive Programming Software Development by Saith …;; number = ReturnChosenNumber(); } return number; } [/CODE] Edit: I changed from using SStream, String, to just cin. The older version used them, but… Re: SStream, String, Integer, And Recursive Programming Software Development by vijayan121 …]#include <type_traits> #include <iostream> #include <sstream> template< typename T = int > T number_from_stdin( const… sstream/string problem Programming Software Development by letterG …: #include<iostream> #include<string> #include<sstream> using namespace std; struct movie{ string title; int year… Strings, Sstream, and the death of both. Programming Software Development by Rimojenkins … is the code [CODE] #include <iostream> #include <sstream> #include <string> using namespace std; int main… Re: Strings, Sstream, and the death of both. Programming Software Development by Rimojenkins … looks like this: [CODE] #include <iostream> #include <sstream> #include <string> using namespace std; int main… Re: SStream, String, Integer, And Recursive Programming Software Development by Saith Odd. The above code seemed to work in a small test program, but once I tried it in my project, it did not work as expected. I changed it slightly to what I've linked below. Seems to work fine now. [CODE] /* Purpose: Create a function to check the input from user. Only valid integer should be returned. All other input should be tossed,… Re: SStream, String, Integer, And Recursive Programming Software Development by WaltP Use the second one. The first one is crap. Re: SStream, String, Integer, And Recursive Programming Software Development by pseudorandom21 Personally I would rather not deal with "cin" failure, but rather a stringstream failure. I'm writing this in the textbox but it usually works when I do: [code] template<class int_type> int_type GetChosenNumber(std::istream &is, std::ostream &os){ int_type out; std::string in; std::getline(is, in); while( (std::… Re: SStream, String, Integer, And Recursive Programming Software Development by mrnutty @OP or a more generic approach: [code] struct InvalidInputException : std::exception{ InvalidInputException(): std::exception("Error: Invalid conversion") {} }; //tries to get a data of type T, throws InvalidInputException if failed template<typename T> T prompt(const std::string msg){ cout << msg ; T res = T(); if( !… Re: SStream, String, Integer, And Recursive Programming Software Development by pseudorandom21 Yes, good point Vijayan, I usually assume it's good input even if it has trailing crud for some reason. Might I ask for an explanation of this line: [quote][icode]typename std::enable_if< std::is_arithmetic<T>::value, T >::type* = 0 )[/icode][/quote] Re: SStream, String, Integer, And Recursive Programming Software Development by vijayan121 > Might I ask for an explanation of this line > [ICODE]typename std::enable_if< std::is_arithmetic<T>::value, T >::type* = 0[/ICODE] Well, the original question was about [CODE]Only valid integer should be returned. All other input should be tossed, user should be asked again for valid integer input.[/CODE] I took the … Re: SStream, String, Integer, And Recursive Programming Software Development by pseudorandom21 Thank you Vijayan121, that is very helpful. Re: SStream, String, Integer, And Recursive Programming Software Development by mrnutty [QUOTE=vijayan121;1576962]> Might I ask for an explanation of this line > [ICODE]typename std::enable_if< std::is_arithmetic<T>::value, T >::type* = 0[/ICODE] Well, the original question was about [CODE]Only valid integer should be returned. All other input should be tossed, user should be asked again for valid integer … Re: SStream, String, Integer, And Recursive Programming Software Development by vijayan121 > wait what does enable_if return if false? Repeat: std::enable_if<> proposal was based on boost::enable_if<>, which is explained here: [url]http://drdobbs.com/cpp/184401659[/url] Alternatively, look up section 20.9.7.6 in the FDIS. Re: sstream/string problem Programming Software Development by Ancient Dragon what compiler are you using? I know Visual Studio 6.0 had a bug that did that but it was fixed with one of its patches. Write another tiny program just to test if your compiler has a similar problem. Re: sstream/string problem Programming Software Development by letterG im using microsoft visual c++ 6.0, so do I have to get a better compiler then? Re: sstream/string problem Programming Software Development by Ancient Dragon get vc++ 2010 express -- its free, so is Code::Blocks/MinGW compiler. Or, download an install SP6 for your compiler from Microsoft web site. I don't know if its still available though. Re: sstream/string problem Programming Software Development by Schol-R-LEA As an aside, you will want to use `int` as the return type of `main()` in the future. Strictly speaking, `void main()` isn't legal C++, even if some compilers accept it. Just a piece of advice, which you may need to know about as most newer compilers will flag `void main()` as erroneous, or at least give a warning. Re: sstream/string problem Programming Software Development by letterG so my code isn't wrong at all then?, well thanks guys! Re: Returning a string. C++ SSTREAM Programming Software Development by LevyDee Send everything you want to output into a string stream(#include <sstream>). [code] std::stringstream ss; ss << "My hero has " << LIFE << "life and " << bla bla bla; return ss.str(); [/code] Re: Strings, Sstream, and the death of both. Programming Software Development by mrnutty Print out your "input" and see if its correctly formatted. Make sure you account for the spaces. Have you learned about classes and structures? >>[QUOTE] I don't want to cheat. This is my major and I have a passion for it, but I can not find this answer in my book[/QUOTE] Give you respect for this. Not many new posters have this … Re: Strings, Sstream, and the death of both. Programming Software Development by Rimojenkins To me, structures would just make it look nicer. I do not know about classes though, so tomorrow I'll open that section and start studying it. The input is correct because the teacher sent it to us. That is what really troubles me. I have to go to bed now to wake up early, but I'll ask the teacher if he can help me tomorrow. If I can find the … Re: Strings, Sstream, and the death of both. Programming Software Development by Rimojenkins [quote]Make sure you account for the spaces[/quote] I now see what you are saying. Thank you for the advice! Converting different types to string, from included file, using templates Programming Software Development by Taniotoshi …lt;unsigned long>(seed); object_to_string = sstream.str(); return object_to_string; }[/CODE] Yeah …) { stringstream sstream (stringstream::out); string variable_to_string; sstream << _variable; variable_to_string = sstream.str(); return … Serialization of Packages Programming Software Development by coolerking …t_file_package *p2; t_stream *stream,*stream2; char * sStream; stream = package_file_serializer(p1); sStream = stream_serializer(stream); stream2 = stream_deserializer(sStream); p2 = package_file_deserializer(stream2); assert(p1->port… Re: Converting different types to string, from included file, using templates Programming Software Development by Taniotoshi … had to also include a <string> and <sstream> in [I]RandomGenerator [/I]and [I]Printer[/I]. Also… Why it is I/O 123 error? Programming Software Development by ipage …FileName, '.'+ FormatFloat('000', i)); newfile:= path+extractfilename(splitfilename); sStream := TFileStream.Create(newfile, fmCreate or fmShareExclusive); try if fs.… then SizeofFiles := fs.Size - fs.Position; sStream.CopyFrom(fs, SizeofFiles); finally sStream.Free; end; end; finally fs.Free; end… C++ String Problem: Encoding & Decoding Strings W/ Enigma Class Programming Software Development by ppotter3 …Driver.cpp #include <string> #include <sstream> #include <iostream> #include <fstream… _ENIGMA_H #include <string> #include <sstream> using namespace std; class Enigma { private: string….h #include <string> #include <sstream> #include <fstream> using namespace std… Class Object Composition problem Programming Software Development by andylbh …<string.h> #include <ostream> #include <sstream> #include <cstdio> #include <vector> #…<iomanip> #include <string.h> #include <sstream> #include <cstdio> #include <vector> #…<fstream> #include <string.h> #include <sstream> #include <cstdio> #include <vector> #… Re: Serialization of Packages Programming Software Development by deceptikon …;); t_file_package *p2; t_stream *stream,*stream2; char * sStream; stream = package_file_serializer(p1); sStream = stream_serializer(stream); stream2 = stream_deserializer(sStream); p2 = package_file_deserializer(stream2); assert(p1->port…