Questions tagged [istream]

In C++ std::istream is the base class for input streams.

696 questions
-1
votes
2 answers

How to new a dynamic array after cin

I'm trying to make a class that contains a pointer, which is the core of a dynamic array. How to overload the operator >> so I can cin >> to the pointer without know how many characters are going to put? I was trying: #include class…
-1
votes
1 answer

How to parse date format from std::cin into stringstream buffer in c++?

Having this class: date.hpp: #ifndef DATE_HPP #define DATE_HPP #include #include #include class Date { std::stringstream format; time_t date; struct tm *date_tm; public: Date() : date(time(NULL)),…
milanHrabos
  • 2,010
  • 3
  • 11
  • 45
-1
votes
1 answer

Use istream and ostream objects as data members of class c++

I am trying to implement a class in which I can't use cin and cout directly. I need to pass reference of input and output streams to the constructor of class and save them in some private fields so that I can access them later in some other function…
-1
votes
1 answer

C++ : how to read to separate variables and then to vector?

Having this: #include #include #include using namespace std; void read_vector(istream &in, vector &vec) { if (in) //check wheter !in.fail() => but how can "cin" have error status?? { …
milanHrabos
  • 2,010
  • 3
  • 11
  • 45
-1
votes
2 answers

Insert data into an istream

I'm reading data from an ifstream. I have an object whose operator>> reads an integer n, an integer m and then n rows of m integers (a matrix). In my ifstream, I have a matrix list but without the integers n and m at the start of each matrix block.…
Sevla
  • 67
  • 1
  • 10
-1
votes
1 answer

Overloaded ( << ) friend function, can't access public class data

I can't seem to access class variables through functions or otherwise, side of my overloaded << friend function. Values appear to be random numbers inside of the functions even though I redefine them in the main. I am in the process of making a…
Gomi
  • 3
  • 3
-1
votes
2 answers

How do I create a loop that lets the user re-enter their answer when a cin.fail() occurs?

This small segment of my program seems to cause some problems: cout << "Would you like to change the values? Type 1 if yes or 2 if no." << endl << "You can also reverse the original vector above by typing 3. \n Answer: "; cin >> yesorno; …
Outliggare
  • 19
  • 2
-1
votes
1 answer

How to count the delimiters and re-read lines from istream file?

I have a one-argument constructor, for a base class, that takes a std::istream& in as a parameter. in is suppose to be a file with fields separated by a comma: c, Toyota , n, 157 r, Jaguar , u, 246, 0.2 c, Honda , b, 145 Each field is supposed…
Error_303
  • 17
  • 2
-1
votes
1 answer

csv parsing with istream extraction operator: How to detect missing field values?

I am trying to do a simple csv(space seperated values) parsing using istream <<(operator). My file csv file format looks as follows: file.csv /names | value | interval | name1 11 1 name2 22 2 name3 33 …
charansai
  • 137
  • 13
-1
votes
1 answer

C++ how to write a ifstream for multiple files?

So I have several files that form a contingent number of lines, so let's call them file1, file2, file3 and so forth. What I want to do is to create a istream class which streams all the files as if they were one. One thing i got is not to subclass…
Kai
  • 376
  • 1
  • 4
  • 17
-1
votes
1 answer

istream opening .txt file but not actually gathering the text within the file

edit: RESOLVED. Moved ins >> val to precede the loop then put ins.fail() as the condition. I'm not entirely sure why this helped but it did and I will gladly be moving forward. Original post: I'm having an issue with the code below. For some reason,…
tanto_
  • 344
  • 2
  • 8
-1
votes
1 answer

c++ reading a file multiple threads

I have a big file, more than 89 million lines. I want to read a file pash it to a hash table and then make some calculations. The problem is that with istream the reading of the file and passing it to the hash table is too slow. Is there any…
-1
votes
1 answer

How does cin object converts characters to different types as user needes?

How does std::cin object deal with different types while it is an instance of basic_istream (istream)?
asmmo
  • 6,922
  • 1
  • 11
  • 25
-1
votes
1 answer

How can I convert an ifstream to an istream

Is there any way I can convert an ifstream to an istream? I have a function called getToken(istream* br) that accepts an istream as the parameter, but within my main() I use an ifstream to read a file, and I must use this same ifstream to call…
-1
votes
1 answer

C++ Overloading istream operator on object with 2d array - Cannot bind error

Hey all I keep getting this error in my istream overload function: ColorBlob.cpp: In function 'std::istream& operator>>(std::istream&, ColorBlob&)': ColorBlob.cpp:204:17: error: cannot bind 'std::istream {aka std::basic_istream}' lvalue to…