Questions tagged [istream]

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

658 questions
-1
votes
1 answer

getline function doesn't exit loop

Essentially I'm creating my own string class called MyString. Within this class there is a function called getline which is supposed to perform exactly like the 'string' class's getline function does. But upon testing, it seems the function…
Quantum
  • 1
  • 1
-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
  • 366
  • 1
  • 4
  • 16
-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_
  • 59
  • 6
-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,409
  • 1
  • 7
  • 22
-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…
-1
votes
3 answers

Simple user request for filename for output and input

How can I request the user to input the filename that my program needs to read from and have it output the name with .out extension instead? Example: char fileName[256]; cout << "What is the file name that should be processed?"; cin >>…
Matt Swezey
  • 351
  • 3
  • 10
  • 25
-1
votes
1 answer

No instance of constructor std::istream_iterator

I have the following problem. I want to create a file constructor for my class. I am using std::copy algorithm and I get this kind of error: No instance of constructor std::istream_iterator ... matches the argument list error C2440:…
-1
votes
1 answer

load a file of 1's and 0's into a char** line by line

I have a file, at the end of each line there is possibly a newline: 111\n 100\n 101
imonaboat
  • 19
  • 6
-1
votes
1 answer

Using CImage.Save (InMemory)

I'm working with some pictures in a MFC application, and I realized that the CImage class (from MFC) has 2 types of save, to a file and to a IStream interface. I'm trying to use that IStream interface to save to memory, using the convention features…
Montes
  • 160
  • 1
  • 7
-1
votes
2 answers

istream operator >> not recognising '\n' character

I am basically reading a .txt file and storing values. For example: Student- Mark Tennis It will store Mark into memory as the studentName. Now...If it is just Student- Tennis Then it will work fine and produce an error. However, if the file…
Sam Thers
  • 67
  • 1
  • 10
-1
votes
1 answer

How to dismiss characters/integers from input text from file?

I have managed to write some code that can read from a .txt file, however I want my program to only read in important data. For example, if my text file had the following data: Name= Samuel Favourite colour= Green Age= 24 Gender= Male I want my…
user4167396
  • 29
  • 1
  • 7
-1
votes
2 answers

Reading file with istream

I am working on a project which involves polymorphism and inheritance. lets assume that the hierarchy of the classes used in the project are: Media ----> Book ----> MediaRegistry and the declaration of each class are as follows: (the classes have…
manpmanp
  • 57
  • 2
  • 6
-1
votes
1 answer

Improving error processing for an istream helper class when using exceptions

I have written a class to control mandatory input on an istream, based on the original idea posted there: https://stackoverflow.com/a/14331519/3723423 . It verifies and skips mandatory formatting chars, a little bit like with scanf(), but with a…
Christophe
  • 54,708
  • 5
  • 52
  • 107
-1
votes
2 answers

\0 character in istream::getline()

What happens if a file contains a \0 character when using istream::getline()? Will be it be omitted or still assigned into a field in the string buffer?
Niklas R
  • 14,369
  • 23
  • 82
  • 179