Questions tagged [ifstream]

ifstream provides an interface to read data from files as input streams.

The C++ standard library type std::ifstream is a specialized std::istream which uses a std::filebuf to read from a file.

Use this tag for questions about std::ifstream or the wide-character version std::wifstream (also ), or the class template std::basic_ifstream. For questions about file I/O in C++ the tags , , and might be relevant. For more general questions about input streams use the or tags.

2140 questions
0
votes
0 answers

Error C2248: cannot access private member (operator =)

I have written a C++ class which includes an ifstream as a member. However, when compiling the class, the following compilation error comes up: Error 1 error C2248: 'std::basic_ifstream<_Elem,_Traits>::operator =' : cannot access private member…
Luke
  • 2,434
  • 9
  • 39
  • 64
0
votes
1 answer

ifstream variable not reading correct character 1

I have an issue with the following code snippet. I have a file referred to with the character array FileName. The file could be basically anything, but in my case it is a file the contains some irrelevant text on the first line and then some lines…
Svalbard
  • 182
  • 2
  • 13
0
votes
2 answers

ifstream opens files named by cin but not when pulled from an array. Any difference between cin and a regular string definition?

TL;DR File names stored as strings in array (using new) - ifstream won't open them (perror returns "No such file or directory"). Swap out array variable with a call to the user to name the file (using cin) - ifstream opens the file. Why? How do I…
0
votes
1 answer

How do I point to an input stream?

Im trying to use a pointer to point to my desired input stream depending on user decision. This is what ive got so far. string fileName = "test.txt"; ifsteam = myFile; myFile.open(fileName.c_str(), ifstream::in); istream * myStream; if…
Tristus
  • 123
  • 1
  • 13
0
votes
2 answers

Reading from text file is not working C++

I am simply want to read text from a file and don't know why code is not working. I have already put correct text file name on folder from where program is running. I must be doing something small. Please highlight issue in code below: //…
Neeraj Kaushik
  • 354
  • 1
  • 5
  • 20
0
votes
2 answers

Array initialization and finding letter frequency

I'm trying to count the frequency of letters inside a string array and setting the frequencies to an array of size of the entire alphabet. I hope I've designed the way so upper/lower cases don't matter. After this, I want to set the letter of…
shoestringfries
  • 279
  • 4
  • 18
0
votes
1 answer

C++ Creating/Parsing Text File Into a Function

I'm trying to take input from a text file to call a function. The function takes 3 int paramaters. Each line in the text file will include each int followed by a space. How do I parse each line, call a function using integers from each line, and…
user3781214
  • 357
  • 1
  • 3
  • 16
0
votes
1 answer

ifstream stopped working in eclipse

I have a C++ project that I haven't used in a year. It used to run perfectly, opening files with: Matrix pmatrix; pmatrix.readFromFile("pmtx.txt"); and in the function: void Matrix::readFromFile(string filename){ ifstream…
dorien
  • 5,265
  • 10
  • 57
  • 116
0
votes
2 answers

How to read non ascii characters from a text file

I found the length using seekg and tellg, then read them into an unsigned char*. The debugger is showing incorrect text though. ifstream is (infile, ifstream::binary); //find length is.seekg (0, is.end); int length = is.tellg(); is.seekg (0,…
Andrew Tsay
  • 1,893
  • 6
  • 23
  • 35
0
votes
2 answers

C++ classes, working with one single file with different users

I have a base class and a derived class. Currently, I am reading each file separately i.e. the carfile and the sportsCarFile. They are then loaded as members to be used for other purposes. I am trying to get my head around how I would read one…
BeginnerLK
  • 33
  • 1
  • 7
0
votes
1 answer

Reading text file cause invalid character at buffer end

Reading a simple text file in c++ display invalid characters at the end of buffer, string filecontent=""; ifstream reader(fileName); reader.seekg (0, reader.end);`` int length = reader.tellg(); reader.seekg (0, reader.beg); …
Ali
  • 557
  • 1
  • 9
  • 30
0
votes
2 answers

Access Violation Writing to location

Im new to c++ and I dont know what this error means. It reads from a file and tries to store the values in a char * []. The file contains: 5,Justin,19,123-45-6789,State Farm,9876,Jessica,Broken Hand, This is my code. void…
user3325783
0
votes
1 answer

Reading a comma delimited file part by part

I have an assignment from school and have to read a comma delimited file and put each value in to a char*. Ex) File contains: 5,Justin,19,123-4567,etc.. char * firstValue = 5; char * secondValue = Justin; char * thirdValue = 123-4567; etc.. I…
user3325783
0
votes
1 answer

How to get cursor to next line after using ">>" operator when reading from file

I am trying to read information from a .txt file that looks as shown below.To read the first 2 lines of integers I use the ">>" operator to read them into an array. My problem is that I want to read the next line(in its entirety) to a string so I…
KoolaidLips
  • 247
  • 1
  • 8
  • 20
0
votes
2 answers

C++ Base Class load function

I have a base class of cars and a load function, if I have a derived class, can I use the load function from the base class and add extra data members such as engine size for sports cars to be loaded from a file. Below is my function…
BeginnerLK
  • 33
  • 1
  • 7
1 2 3
99
100