• How to write to middle of a file in C++? 2018-10-10

    I think this should be quite simple, but my googling didn't help so far... I need to write to an existing file in C++, but not necessarily at the end of the file. I know that when I just want to append text to my file, I can pass the flag ios:app whe

    Tags: fstream, ofstream, ifstream
  • ifstream and ofstream or fstream using in and out 2018-07-14

    When dealing with files, which of the two examples below is preferred? Does one provide better performance than the other? Is there any difference at all? ifstream input("input_file.txt"); ofstream output("output_file.txt"); vs fstream

    Tags: fstream, ofstream, ifstream
  • std::ofstrean doesn't work with -O3 2016-06-28

    The following code, simply 1) takes an input file name from the command line argument, say in.txt 2) append the file name to "cdf_" 3) open a file with new name cdf_in.txt 4) simply read each line from (a number in each line) and send it to the

    Tags: fstream
  • Extracting double values from file into array 2015-02-09

    I am trying to extract double values from 2 different text files and will be putting them in arrays. Here is a snippet of the code: #include <cstdlib> #include <iostream> #include <fstream> using namespace std; int main() { int p; c

    Tags: arrays, fstream
  • C++ fstream not working properly 2015-02-04

    This program is executing without giving any error. But nothing seems to be written or read from test.txt. Please help me spot the mistake. I feel I have implemented ofstream and ifstream correctly. I am unable to spot what I am missing. #include

    Tags: fstream
  • Using fstream and fstream.eof. Working with files 2014-12-29

    I'm trying to make a programm, which will read the file, change specified word to symbols '@' and write back to same file. But I have problems with that. 1st question. It seems like I need to store file in buffer before writing it to the file. How sh

    Tags: file, fstream
  • seekp() position at the beginnig of new line in file 2014-12-15

    I have a file "first.txt": Chun mee |Wuyi |Genmai | Pu-erth |Green |Flower mix | Lightly sweet|Strong,smooth|Fresh, strong| Here '|' is delimiter, the first line has 10 symbols in each block (block is the space between delimiters), the second - 11, t

    Tags: file io, fstream
  • C++ std::istream readsome doesn't read anything 2014-11-24

    It's like readsome isn't even reading. Returns 0 and doesn't read any chars. What is wrong here? #include <fstream> #include <iostream> int main () { std::fstream stream("list.cpp", std::ios::in); if (stream.good() || !stream.bad() || str

    Tags: fstream, istream
  • Issue reading line from file with getline() 2014-11-24

    I have my readFile() method set up so that my 'myList' vector stays updated, but when I run the program my vector is empty despite my addItem() method properly writing to the file. I've tried looking around for issues regarding ifstream and getline b

    Tags: fstream, getline, ifstream
  • C++ reading txt file and cout values not reading whole file 2014-09-19

    I am trying to read in some values in a txt file like so val1 val2 val3 val1 val2 val3 val1 val2 val3 Then I am trying to cout to the terminal when I compile the program. The problem I am having is the first line of the text file gets read and prints

    Tags: fstream
  • Reading a null terminated string from a binary file c++ 2014-08-08

    As the title says I'm trying to read a null terminated string from a binary file. std::string ObjElement::ReadStringFromStream(std::ifstream &stream) { std::string result = ""; char ch; while (stream.get(ch) != '') { result += ch; } return result

    Tags: fstream
  • reading and writing UTF16 file using fstream in c++ 2014-05-09

    I'm not familiar with c++ stream things. so I practice stream input, output. of course, fstream as well. It's not problem to read and write a file encoded on mutibyte character based encoding, but I got stuck when wide character like utf16. here is m

    Tags: fstream
  • After using mkdir() to create a folder how do I have the program save files and other information into the the new folder 2014-03-25

    So this program creates a folder in the program itself with is great but how would I have it save the new file in the folder it just created. #include <iostream> #include <direct.h> #include <string> #include <fstream> using n

    Tags: fstream, mkdir
  • Missing data when reading binary file in C++ 2014-02-20

    vector<byte> h; ifstream fin(file.c_str(), ios::binary); if(!fin) return false; byte b; while(fin >> b) h.push_back(b); The length of h is 4021, while the raw file length is 4096 bytes. But the code below gives a string of 4096 bytes. Why

    Tags: fstream, ifstream
  • Complex C++ Text File IO 2013-11-01

    I want to create a reusable program that creates a random multiple choice test out of a text file. The text file would hold the question, answer, and other incorrect answers. I want the program to search for keywords that identify parts of the text f

    Tags: parsing, fstream
  • fstream: the most correct way to check for errors 2013-07-05

    I want to write a wrapper around fstream class. As I can see the most common way to check if stream works well is to see result of good() function. However, I've heard that this is mostly historical function and it is not really safe to use it (to be

    Tags: exception, error handling, fstream
  • C++ Program in Xcode not outputting simple text file using outFile 2013-05-27

    I am running a program using this simple example code to output a text file. I am using Xcode and simply started a new C++ project from command line tools. For some reason the program does not output any file onto my Mac. Please help figure out why X

    Tags: file io, fstream
  • I can access a static fstream from one file only 2012-04-30

    I need to use a static fstream in multiple source files. However I can only use it from a single file and not from the others. Furthermore, its use in the other files does not give any error, it just does nothing. This is the code: /// log.h #ifndef

    Tags: static, fstream, extern
  • Is it possible to pass cout or fout to a function? 2012-04-27

    I'm trying to find a way to pass fout or cout to a function. I realize there are logically easy ways to deal with this, like put ifs in any function that outputs data or even just write the function both ways. However, that seems primitive and ineffi

    Tags: fstream, ofstream
  • Segfault 11 in code using vectors and fstream? C++ 2012-04-25

    Im trying to write a program that takes a txt file as input, and uses ques from the words in the text file to generate a .h file (and later hopefully) a .cpp file. This code compiles fine, its just that it segfault 11's once it gets the input file. C

    Tags: fstream, vector, segmentation fault

Copyright (C) dskims.com, All Rights Reserved.

processed in 4.548 (s). 9 q(s)