istream

Passing istream into a function

旧时模样 提交于 2019-12-14 04:25:21
问题 I am making a game-type program similar to the idea of pokemon. We have a tournament class that keeps track of several teams(its own class) which consists of pets(its own class) with different kinds of pets being subclasses of CPet. We are attempting to pass a file name into main, from main pass that file name into the Tournament class. In the Tournament class we open the file with: 14 //Construct a tournament 15 CTournament::CTournament(const char *Filename){ 16 //opening file 17 ifstream

Inline ignore in Streams

余生颓废 提交于 2019-12-13 18:27:35
问题 Is there a way to ignore characters in C++ inline? For example in this answer I'm reading in: istringstream foo("2000-13-30"); foo >> year; foo.ignore(); foo >> month; foo.ignore(); foo >> day; But I'd like to be able to do this all inline: foo >> year >> ignore() >> month >> ignore() >> day; I thought this was possible in C++, but it definitely isn't compiling for me. Perhaps I'm remembering another language? 回答1: foo.ignore() is a member function so it can't be used as a manipulator. It

Opening stream via function

北战南征 提交于 2019-12-12 12:40:14
问题 I need help with the non-copyable nature of [io](f)stream s. I need to provide a hackish wrapper around fstream s in order to handle files with unicode characters in their filenames on Windows. For this, I devised a wrapper function: bool open_ifstream( istream &stream, const string &filename ) { #ifdef __GLIBCXX__ FILE* result = _wfopen( convert_to_utf16(filename).c_str(), L"r" ); if( result == 0 ) return false; __gnu_cxx::stdio_filebuf<char>* buffer = new __gnu_cxx::stdio_filebuf<char>(

input iterator skipping whitespace, any way to prevent this skipping

别来无恙 提交于 2019-12-12 10:44:18
问题 I am reading from a file into a string until I reach a delimitting character, the dollar symbol. But the input iterator is skipping whitespace so the string created has no spaces. not what I want in this case. Is there any way to stop the skipping behaviour? and if so how? Here is my test code. #include <iostream> #include <fstream> #include <iterator> #include <string> // istream iterator is skipping whitespace. How do I get all chars? void readTo(std::istream_iterator<char> iit, std::string

Implementing istream in a C++ Fraction Calculator

痴心易碎 提交于 2019-12-12 05:34:57
问题 I am trying to learn the object oriented programming and make the simple fraction calculator than can add or subtract any number of functions and write the answer as a reduced fraction. Example: input= 3/2 + 4/ 8 , output = 2 I am trying overload operators in order to accomplish this. So in the program, I am trying to develop the input consists of an expression made of fractions separated by the operators '+'or '-'. The number of fractions in the expression is arbitrary. Each of the following

Decrypted file has strange characters after AES CBC decryption process

ⅰ亾dé卋堺 提交于 2019-12-12 04:39:27
问题 I am decrypting a file with AES CBC method using the Cryptopp library in vc++, VS2015 and QT libraries. I could obtain a result file decrypted but there are some characters which are not being decrypted correctly. The code I use is: const std::string encrypted_file("C:\\TEMP\\G0030013.xml"); const std::string decrypted_file("C:\\TEMP\\decrypted0.xml"); const int key_size(CryptoPP::AES::DEFAULT_KEYLENGTH); const int iv_size(CryptoPP::AES::BLOCKSIZE); CryptoPP::CBC_Mode<CryptoPP::AES>:

Overloading >> operator for Date class in c++ causes infinite loop

元气小坏坏 提交于 2019-12-11 19:48:34
问题 I'm trying to overload the >>operator for a Date class in c++ but the it goes in infinite loop when the run goes into the first if statement, can you please help me? //operator istream& operator >>(istream& is,CustomDate& d){ int day,month,year; char ch1,ch2; string test; is>>skipws>>day>>ch1>>month>>ch2>>year; if(!is){ is.clear(ios_base::failbit); return is; } if(ch1!='/' || ch2!='/') error("invalid date input"); d = CustomDate(day,month,year); return is; } This is the function that calls it

Someway to buffer or wrap cin so I can use tellg/seekg?

混江龙づ霸主 提交于 2019-12-11 17:20:05
问题 Is there any way to add buffering to cin so that I can effectively use tellg and seekg on that istream? (I only need to go back about 6 characters.) Or is there perhaps some way to wrap the stream with a (perhaps custom) istream object that acts as a buffered pipe that would allow me to use tellg/seekg to revert the stream position a few characters? It might look like this: BufferedIStream bis(cin); streampos pos = bis.tellg(); MyObjectType t = getObjectType(bis); bis.seekg(pos); As a work

PInvoke and IStream

◇◆丶佛笑我妖孽 提交于 2019-12-11 17:13:39
问题 I have an exported function from a dll written in c++ with the following signiture: Foo( LPSTREAM *pStream, UINT &Size ) that returns an memory stream and obviously its size. What I am having difficulties with is creating a signiture for the exported function and then attempting to read the stream in C#. At one point was able to use "unsafe" byte pointer to get the information, but this does not fit our requirements. Any thoughts, examples, samples etc would be greatly appreciated. 回答1: You

best way to upload uint8_t array to azure blob storage with wastorage in c++

十年热恋 提交于 2019-12-11 12:47:56
问题 I would like to upload a uint8_t array to azure storage using the azure storage SDK. I m struggling to construct the input stream from the array, I managed to get something that compile by using a std::vector but that require an extra copy of the array. Do you think of a better way? void upload(azure::storage::cloud_blob_container container, const wchar_t* blobName, const uint8_t * data, size_t dataLength) { std::vector<uint8_t> bytes(dataLength, (const unsigned char)data); concurrency: