Hello guys! I'm having a rather pesky problem working with fstream. I could write, for example: [CODE]fstream file("text.txt");[/CODE] then file should be open in read/write mode. But then if I do the following: [CODE]file << "Some text"; file >> string_var;[/CODE] or in the opposite order, it will only perform the first operation. I've even tried with seekp() but it still happens, even if I do: [CODE]file.open("text.txt",ios::out); file << "A word!"; file.close(); file.open("text.txt",ios::in); file >> aString;[/CODE] The only way i've found to fix this is creating two separate fstreams but it seems not right... Also, if I try to open different …

Member Avatar
Member Avatar
+0 forum 1

Hi I need help on this please.I have to write a void function that reads data from the following file:5 2 2 670.60 6 4 2 890.80 2 2 0 220.00 10 8 1 1340.60 10 4 3 1430.70 4 0 0 460.30 5 3 1 700.00 7 5 2 1100.80 3 1 0 340.80. and then do some math on it,but I am struggling to get the function to read the data line by line,it is reading only the last line. Please if you can help,I will appreciate it!

Member Avatar
Member Avatar
+0 forum 16

Hi, I'm writing a scientific application that has to store a large (1GB to 500GB+) amount of data on a hard drive, and then, once written, read it back sequentially to process it. The amount of data for a particular experiment is known in advance, exact to the byte. When I write this file to disk at the moment, it ends up extremely fragmented (500+ fragments), despite there being enough contiguous space on the drive at the start to have it in one piece. This ends up being extremely detrimental to performance when analysing the data. I imagine this happens …

Member Avatar
Member Avatar
+0 forum 4

Hello, I am more experienced with Java and trying to write a script for a server I have. I need to learn Python anyway, so I am attempting to do it in python. I am not completely lost, but just puzzled why it would do this. Here is the code [CODE= Python] #!/usr/bin/env python import sys import os from optparse import OptionParser #displays help usage = "usage:%prog [options] arg" description = "Creates a Django project with the necessary files to get a website running on a apache server." parser = OptionParser(usage=usage, description=description) parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True, help="don't print status …

Member Avatar
Member Avatar
+0 forum 1

i have the following code...according to my book both the files should open...but it opens both the files...writes into them....but when i open them for reading....only one opens up....pls see where i am wrong....[CODE] #include<iostream> #include<fstream> using namespace std; int main() { ofstream fout; fout.open("country.txt"); fout<<"United States of America\n"; fout<<"United Kingdom\n"; fout<<"South Korea\n"; fout.close(); fout.open("capital.txt"); fout<<"Washington\n"; fout<<"London\n"; fout<<"Seoul\n"; fout.close(); const int n= 80; char line[n]; ifstream fin; cout<<"\nContents of capital file\n"; fin.open("capital.txt",ios::in); fin.getline(line, n); cout<<line; }while(fin); fin.close(); fin.open("country.txt"); cout<<"\nContents of country file"; do { fin.getline(line, n); cout<<line; }while(fin); fin.close(); system("pause"); } [/CODE]

Member Avatar
Member Avatar
+0 forum 1

THis is what I need to do...I need help with the third point [INDENT]1. Write a class OrderedList. The implementation of OrderedList must be as a linked list of Comparable elements. The list items are maintained in ascending order at all times. On this assignment, no indexing methods are allowed. The following methods are required: int size() //Return the number of items in the list boolean contains(Comparable item)//Return true iff item is stored in the OrderedList void insert(Comparable item)//Add an item to the OrderedList Comparable remove(Comparable item) //Remove and return a matching item Also, provide a default constructor and a …

Member Avatar
Member Avatar
+0 forum 8

When my code (below) is executed, a error message is triggered which says "The operation completed successfully." To give this some context, hFileMap is valid; I have checked this with my debugger, and other operations can easily be performed correctly on this handle that yield correct results. The only weird thing is that MapViewOfFile returns a null pointer. Since I use this memory mapped file as a way of communicating between two applications, this function is critical. Please note that I am no beginner to coding, and this same program successfully implements multi-threading as well as on-the-fly (dynamic) function creation …

Member Avatar
Member Avatar
+0 forum 2

Hi, I want to create a log file that captures all the actions happening...anyway i got code for that from internet. Now what i want to do is, make that [COLOR="Red"][U][B]file read only[/B][/U][/COLOR] so that the data is not modified by external application or user. [code=c++]log(char* msg) { time_t now = time(0); struct tm* tm = localtime(&now); ofstream out( "logfileBrandNew.log",ios::app); out << tm->tm_year << '/' << tm->tm_mon << '/' << tm->tm_mday << ' ' << tm->tm_hour << ':' << tm->tm_min << ':' << tm->tm_sec << ": "; out << msg << "\n"; out.close(); }[/code] How to achieve this using c++ …

Member Avatar
Member Avatar
+0 forum 11

I am working on an application and would like to be able to calculate the efficiency of various algorithms and choose the best one. The application operates on a list of records that are stored in a file. Operations include adding records, deleting records, and searching for records based on any field in the record. I know that the File I/O and searching has cost and I am having trouble find a balance between them. Is it more desirable to minimize search time or File I/O? For example, I could use the search from the STL, but that would require …

Member Avatar
Member Avatar
+0 forum 3

Hello everyone, I currently have an application that reads in an entire excel file then iterates through the records from the file and queries our database for a match. If a match is found the record is ignored if a match is not found the record gets added to the database. Now there are ~2500 records per excel file and each of those records has a few attributes linked to it. My problem is that when I try to read in certain files I get a GC overhead error or out of memory error. To resolve this I know I …

Member Avatar
Member Avatar
+0 forum 2

Aslam o Alikum to all, here is my code to get and change the attributes of a txt file. I want to change the hidden attribute of file. In this code, when i get attribute of file, the number 20 (100000) is returned in cx. I changed this number to 22(100010) ie i have set the hidden attribute. But when I run the program, the no changes are applied. please help me.

Member Avatar
Member Avatar
+0 forum 1

For this project i need to have the ability to analyze a file containing a number of .NET(3.5) class's from source code.. identify every class and then output each seperate class into their own text file i.e(this is what the file is like, contains a number of class's in it, one after another)) [class 1 attributes] class 1 {code} [class 2 attributes] class 2 {code} What do you think would be the best way to do this? What i was thinking of doing is somehow using regex's to identify [attributes] and the beginning of class's and then save the text(code) …

Member Avatar
+0 forum 0

I'm reading in a text file that contains a little custom script. However, one line of that script gets ignored and I can't figure out why. Script: [CODE]# Test Case #1 - Simple Movement RESET FORWARD 2 PAUSE 1 REVERSE 2 PAUSE 2 TURNRIGHT 2 PAUSE 1 TURNLEFT 2 PAUSE 2 RESET[/CODE] Program: [CODE]int main( void ) { /* Declare variables */ FILE *file; char line[80]; char *tokenPtr; char fileName[6]; printf( "Enter the name of the file to be read.\n" ); gets( fileName ); printf( "\n" ); file = fopen( fileName, "r" ); /* Create "Test.txt" for reading */ if …

Member Avatar
Member Avatar
+0 forum 1

Hello everyone! I am using python 2.6 on cygwin environment and wondering how could i prevent two python processes from writing to a file at the same time. The file that is shared between the python processes is an ini file and is accessed through ConfigObj module. The first python process is a daemon which runs indefinitely writing to the ini file, data on some random external conditions. The other python processes, start occasionally (one at a time), execute their code, write data on the ini file and stop. The command i want to ensure that is safely executed in …

Member Avatar
Member Avatar
+0 forum 5

hi I have been looking around for a good file io tutorial and I cant find any. It is simple enough to me the process, mov dx,043h mov al,54 out dx,al etc. but i have no idea which ports go to where or how to write to a hard disk or floppy drive etc. how do i find out which ports map to where?

Member Avatar
Member Avatar
+0 forum 6

hey guys/gals. how do i save to a file the data that is printed by this program i wrote. I have the code to do this in the createFile function but i am unsure in how to output what was printed. Any suggestions? [CODE]//class member functions #include "experiment.h" Experiment::Experiment() { numberOfTests = 0; } void Experiment::setExpName() { cin.ignore(1); cout << "Please enter a tag name for this experiment: "; getline(cin, name); } string Experiment::getExpName() { return name; } void Experiment::setPersonForExperiment() { cout << "Please enter the name of person responsible for conducting this experiment: "; getline(cin, who); } string Experiment::getPersonForExperiment() …

Member Avatar
Member Avatar
+0 forum 2

Hello, I was trying to implement data structures using file operations. I am using a data structure of two integers, one being the index number and other being the value. My actual aim is to recreate the file containing the data using a log. But, the program isn't running as required. Please help. I am giving the code: [CODE] ifstream rlist; rlist.open("redo.txt",ios::in); ofstream datt; datt.open("datatemp.txt",ios::out); dat c; char s; while(!rlist.eof()){ rlist>>s; if(s=='I'){ rlist.read((char*) &c,sizeof c); datt.write((char*) &c,sizeof c); } if(s=='D'){ ifstream rlistd; rlistd.open("datatemp.txt",ios::in); rlist.read((char*) &c,sizeof c); ofstream rlistdw; dat s; rlistdw.open("datatem.txt",ios::out); while(!rlistd.eof()){ rlistd.read((char *) &s, sizeof s); if((s.a)!=(c.a)) rlistdw.write((char*) &s, …

Member Avatar
Member Avatar
+0 forum 5

I am having trouble adding information from a ".txt" file to a linked list... here is what i have. list1.txt: 1 2 4 5 6 7 8 11 [CODE] /** The LinkedList1 class implements a Linked list. */ class LinkedList1 { /** The Node class stores a list element and a reference to the next node. */ private class Node { String value; Node next; /** Constructor. @param val The element to store in the node. @param n The reference to the successor node. */ Node(String val, Node n) { value = val; next = n; } /** Constructor. @param …

Member Avatar
Member Avatar
+0 forum 2

how do i read in files from a ".txt" file into a linked list heres my code. [CODE] import java.io.*; public class LinkedList1 { class Node { String element; // list element Node next; // successor link Node(String el, Node n) { element = el; next = n; } Node(String el) { element = el; next = null; } } public static main (String[] args) { Node myList = new Node("1"); // AT THIS PART OF MY CODE I WANT TO READ IN INTEGERS FROM A ".txt" FILE // USING FILE IO HOW DO I DO THAT? } } [/CODE]

Member Avatar
Member Avatar
+0 forum 1

Hi all, I need to store some data in a txt file from a textbox.text. I have try this and works: [code] FileInfo t = new FileInfo("data.txt"); StreamWriter Txt =t.CreateText(); Txt.WriteLine(textbox1.text); Txt.Close(); [/code] But.... How can I create multiple files without delete the older one, e.g., Gives the name to the file like "current time and date".txt This code is to use with a button click event. Thanks a lot, Chrom

Member Avatar
Member Avatar
+1 forum 5

I got this silly problem and honestly dunno why it isnt working . The scenario is i got a text file with information and i got to print the ASCII equivalent of the text into the screen . While attempting to do so , i am getting the binary equivalent (well apparently it doesnt seem so ). [code] #include <iostream> #include <fstream> using namespace std; int main () { int c; char str[10]; ifstream is; cout << "Enter the name of an existing text file: "; cin.get (str,10); is.open (str); // open file while (is.good()) // loop while extraction from …

Member Avatar
Member Avatar
+0 forum 7

The End.