Search Results

Search found 209 results on 9 pages for 'fstream'.

Page 3/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • Reading and writing to files simultaneously?

    - by vipersnake005
    Moved the question here. Suppose, I want to store 1,000,000,000 integers and cannot use my memory. I would use a file(which can easily handle so much data ). How can I let it read and write and the same time. Using fstream file("file.txt', ios::out | ios::in ); doesn't create a file, in the first place. But supposing the file exists, I am unable to use to do reading and writing simultaneously. WHat I mean is this : Let the contents of the file be 111111 Then if I run : - #include <fstream> #include <iostream> using namespace std; int main() { fstream file("file.txt",ios:in|ios::out); char x; while( file>>x) { file<<'0'; } return 0; } Shouldn't the file's contents now be 101010 ? Read one character and then overwrite the next one with 0 ? Or incase the entire contents were read at once into some buffer, should there not be atleast one 0 in the file ? 1111110 ? But the contents remain unaltered. Please explain. Thank you.

    Read the article

  • How do I use Java to sort surnames in alphabetical order from file to file?

    - by user577939
    I have written this code and don't know how to sort surnames in alphabetical order from my file to another file. import java.io.*; import java.util.*; class Asmuo { String pavarde; String vardas; long buvLaikas; int atv1; int atv2; int atv3; } class Irasas { Asmuo duom; Irasas kitas; } class Sarasas { private Irasas p; Sarasas() { p = null; } Irasas itrauktiElementa(String pv, String v, long laikas, int d0, int d1, int d2) { String pvrd, vrd; int data0; int data1; int data2; long lks; lks = laikas; pvrd = pv; vrd = v; data0 = d0; data1 = d1; data2 = d2; Irasas r = new Irasas(); r.duom = new Asmuo(); uzpildymasDuomenimis(r, pvrd, vrd, lks, d0, d1, d2); r.kitas = p; p = r; return r; } void uzpildymasDuomenimis(Irasas r, String pv, String v, long laik, int d0, int d1, int d2) { r.duom.pavarde = pv; r.duom.vardas = v; r.duom.atv1 = d0; r.duom.buvLaikas = laik; r.duom.atv2 = d1; r.duom.atv3 = d2; } void spausdinti() { Irasas d = p; int i = 0; try { FileWriter fstream = new FileWriter("rez.txt"); BufferedWriter rez = new BufferedWriter(fstream); while (d != null) { System.out.println(d.duom.pavarde + " " + d.duom.vardas + " " + d.duom.buvLaikas + " " + d.duom.atv1 + " " + d.duom.atv2 + " " + d.duom.atv3); rez.write(d.duom.pavarde + " " + d.duom.vardas + " " + d.duom.buvLaikas + " " + d.duom.atv1 + " " + d.duom.atv2 + " " + d.duom.atv3 + "\n"); d = d.kitas; i++; } rez.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } } public class Gyventojai { public static void main(String args[]) { Sarasas sar = new Sarasas(); Calendar atv = Calendar.getInstance(); Calendar isv = Calendar.getInstance(); try { FileInputStream fstream = new FileInputStream("duom.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String eil; while ((eil = br.readLine()) != null) { String[] cells = eil.split(" "); String pvrd = cells[0]; String vrd = cells[1]; atv.set(Integer.parseInt(cells[2]), Integer.parseInt(cells[3]), Integer.parseInt(cells[4])); isv.set(Integer.parseInt(cells[5]), Integer.parseInt(cells[6]), Integer.parseInt(cells[7])); long laik = (isv.getTimeInMillis() - atv.getTimeInMillis()) / (24 * 60 * 60 * 1000); int d0 = Integer.parseInt(cells[2]); int d1 = Integer.parseInt(cells[3]); int d2 = Integer.parseInt(cells[4]); sar.itrauktiElementa(pvrd, vrd, laik, d0, d1, d2); } in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } sar.spausdinti(); } }

    Read the article

  • Getting Segmentation Fault in C++, but why?

    - by Carlos
    I am getting segmentation fault in this code but i cant figure out why. I know a segmentation fault happens when a pointer is NULL, or when it points to a random memory address. #include <iostream> #include <fstream> #include <cmath> using namespace std; //**************************** CLASS ******************************* class Database { struct data{ string city; float latitude, longitude; data *link; }*p; public: Database(); void display(); void add(string cityName, float lat, float lon); private: string cityName; float lat, lon; }; //************************** CLASS METHODS ************************** Database::Database() { p = NULL; } void Database::add(string cityName, float lat, float lon){ data *q, *t; if(p == NULL){ p = new data; p -> city = cityName; p -> latitude = lat; p -> longitude = lon; p -> link = NULL; } else{ q = p; while(q -> link != NULL){ q = q -> link; } t = new data; t -> city = cityName; t -> latitude = lat; t -> longitude = lon; q -> link = t; } } void Database::display() { data *q; cout<<endl; for( q = p ; q != NULL ; q = q->link ) cout << endl << q -> city; } //***************************** MAIN ******************************* //*** INITIALIZATION *** Database D; void loadDatabase(); //****** VARIABLES ***** //******* PROGRAM ****** int main() { loadDatabase(); D.display(); } void loadDatabase() { int i = 0; string cityName; float lat, lon; fstream city; city.open("city.txt", ios::in); fstream latitude; latitude.open("lat.txt", ios::in); fstream longitude; longitude.open("lon.txt", ios::in); while(!city.eof()){ //************************************ city >> cityName; //* * latitude >> lat; //Here is where i think is the problem longitude >> lon; //* * D.add(cityName, lat, lon); //************************************ } city.close(); latitude.close(); longitude.close(); } This is the error am actually getting in console

    Read the article

  • sort surname in alphabet from file to file JAVA

    - by user577939
    hello all. I need some help. I have wrote this code and dont now how to sort surnames in alphabet from my file to other file. import java.io.; import java.util.; class Asmuo { String pavarde; String vardas; long buvLaikas; int atv1; int atv2; int atv3; } class Irasas { Asmuo duom; Irasas kitas; } class Sarasas { private Irasas p; Sarasas() { p = null; } Irasas itrauktiElementa(String pv, String v, long laikas, int d0, int d1, int d2) { String pvrd, vrd; int data0; int data1; int data2; long lks; lks = laikas; pvrd = pv; vrd = v; data0 = d0; data1 = d1; data2 = d2; Irasas r = new Irasas(); r.duom = new Asmuo(); uzpildymasDuomenimis(r, pvrd, vrd, lks, d0, d1, d2); r.kitas = p; p = r; return r; } void uzpildymasDuomenimis(Irasas r, String pv, String v, long laik, int d0, int d1, int d2) { r.duom.pavarde = pv; r.duom.vardas = v; r.duom.atv1 = d0; r.duom.buvLaikas = laik; r.duom.atv2 = d1; r.duom.atv3 = d2; } void spausdinti() { Irasas d = p; int i = 0; try { FileWriter fstream = new FileWriter("rez.txt"); BufferedWriter rez = new BufferedWriter(fstream); while (d != null) { System.out.println(d.duom.pavarde + " " + d.duom.vardas + " " + d.duom.buvLaikas + " " + d.duom.atv1 + " " + d.duom.atv2 + " " + d.duom.atv3); rez.write(d.duom.pavarde + " " + d.duom.vardas + " " + d.duom.buvLaikas + " " + d.duom.atv1 + " " + d.duom.atv2 + " " + d.duom.atv3 + "\n"); d = d.kitas; i++; } rez.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } } public class Gyventojai { public static void main(String args[]) { Sarasas sar = new Sarasas(); Calendar atv = Calendar.getInstance(); Calendar isv = Calendar.getInstance(); try { FileInputStream fstream = new FileInputStream("duom.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String eil; while ((eil = br.readLine()) != null) { String[] cells = eil.split(" "); String pvrd = cells[0]; String vrd = cells[1]; atv.set(Integer.parseInt(cells[2]), Integer.parseInt(cells[3]), Integer.parseInt(cells[4])); isv.set(Integer.parseInt(cells[5]), Integer.parseInt(cells[6]), Integer.parseInt(cells[7])); long laik = (isv.getTimeInMillis() - atv.getTimeInMillis()) / (24 * 60 * 60 * 1000); int d0 = Integer.parseInt(cells[2]); int d1 = Integer.parseInt(cells[3]); int d2 = Integer.parseInt(cells[4]); sar.itrauktiElementa(pvrd, vrd, laik, d0, d1, d2); } in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } sar.spausdinti(); } }

    Read the article

  • Additional spaces in String having read text file to String using FileInputStream

    - by David
    Hi, I'm trying to read in a text file to a String variable. The text file has multiple lines. Having printed the String to test the "read-in" code, there is an additional space between every character. As I am using the String to generate character bigrams, the spaces are making the sample text useless. The code is try{ FileInputStream fstream = new FileInputStream(textfile); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); //Read corpus file line-by-line, concatenating each line to the String "corpus" while ((strLine = br.readLine()) != null) { corpus = (corpus.concat(strLine)); } in.close(); //Close the input stream } catch (Exception e) {//Catch exception if any System.err.println("Error test check: " + e.getMessage()); } I'd be grateful for any advice. Thanks.

    Read the article

  • Problem compiling c++ in CodeGear

    - by Carlos
    I have written a C++ program for a University assignment. I used Netbeans 6.8 running on my Mac and the code runs smoothly, no warnings, errors or problems/bugs. However when compiling and running on a Windows computer using CodeGear RAD Studio 2009 (C++ Builder) am getting several errors. [BCC32 Error] main.cpp(51): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string' [BCC32 Error] main.cpp(62): E2093 'operator==' not implemented in type 'string' for arguments of the same type [BCC32 Error] main.cpp(67): E2093 'operator==' not implemented in type 'string' for arguments of the same type [BCC32 Error] main.cpp(112): E2093 'operator==' not implemented in type 'string' for arguments of the same type [BCC32 Error] main.cpp(121): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string' [BCC32 Error] main.cpp(130): E2093 'operator==' not implemented in type 'string' for arguments of the same type [BCC32 Error] main.cpp(133): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string' [BCC32 Error] main.cpp(139): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string' [BCC32 Error] main.cpp(153): E2094 'operator<<' not implemented in type 'fstream' for arguments of type 'string' [BCC32 Error] main.cpp(199): E2094 'operator>>' not implemented in type 'fstream' for arguments of type 'string' [BCC32 Error] main.cpp(219): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string' [BCC32 Error] main.cpp(231): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string' [BCC32 Error] main.cpp(240): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string' [BCC32 Error] main.cpp(262): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string' [BCC32 Error] main.cpp(264): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string' These are the header files am using #include <iostream> #include <fstream> #include <cmath> #include <stdio> #include <windows> //I added this one just to check and still does not work (I didnt have it on Netbeans/Mac) using namespace std; Any ideas what is producing the errors and how can I fix it?

    Read the article

  • XmlSerializer.Serialize doesn't save a file and doesn't throw an exception.

    - by Wodzu
    Hi guys. I am having problem with saving of my object. Take a look at this code: public void SerializeToXML(String FileName) { XmlSerializer fSerializer = new XmlSerializer(typeof(Configuration)); using (Stream fStream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None)) { fSerializer.Serialize(fStream, this); } } The problem is that when the user does not have rights to the location on hard disk, this function will not throw me any exception and do not save my file. For example saving to "C:\test.xml" act like nothing happened. And I would like to know if the file has not been saved and it would be good to know the reason why. I know that I could check if the file on given location exists and throw an exception manualy but shouldn't this be done by the XmlSerializer or FileStream itself? Thanks for your time

    Read the article

  • Getline and 16h (26d) character

    - by Kra
    Hi, in VC++ environment Im using (string) getline function to read separate lines in opened file. Problem is that getline takes character 1Ah as end of file and if it is present on the line, whole reading ends prematurely. Is there any solution for this? Code snippet: fstream LogFile (Source,fstream::in); string Line while (getline(LogFile,Line)) { .... } File contents: line1text1asdf line2text2asd //EOF for getline here line3asdas // this line will never be read by getline Thank you for any info. Kra

    Read the article

  • Why can't I reserve 1,000,000,000 in my vector ?

    - by vipersnake005
    When I type in the foll. code, I get the output as 1073741823. #include <iostream> #include <vector> using namespace std; int main() { vector <int> v; cout<<v.max_size(); return 0; } However when I try to resize the vector to 1,000,000,000, by v.resize(1000000000); the program stops executing. How can I enable the program to allocate the required memory, when it seems that it should be able to? I am using MinGW in Windows 7. I have 2 GB RAM. Should it not be possible? In case it is not possible, can't I declare it as an array of integers and get away? BUt even that doesn't work. Another thing is that, suppose I would use a file(which can easily handle so much data ). How can I let it read and write and the same time. Using fstream file("file.txt', ios::out | ios::in ); doesn't create a file, in the first place. But supposing the file exists, I am unable to use to do reading and writing simultaneously. WHat I mean is this : Let the contents of the file be 111111 Then if I run : - #include <fstream> #include <iostream> using namespace std; int main() { fstream file("file.txt",ios:in|ios::out); char x; while( file>>x) { file<<'0'; } return 0; } Shouldn't the file's contents now be 101010 ? Read one character and then overwrite the next one with 0 ? Or incase the entire contents were read at once into some buffer, should there not be atleast one 0 in the file ? 1111110 ? But the contents remain unaltered. Please explain. Thank you.

    Read the article

  • "An access violation (Segmentation Fault) raised in your program."

    - by Mark
    My C++ program compiles and works up until I call this function from main(): int uword(){fstream infile("numbers.txt"); fstream exfile("wordlist.txt"); string numb[numoflines]; string lines[numoflines]; number = 1; line = 1; for(int i=0;!infile.eof();++i) { getline (infile,number); numb[i] = number; getline (exfile,line); lines[i] = line; } infile.close(); exfile.close(); string yourword; Something here causes it to crash, in the debug it pops up with "An access violation (Segmentation Fault) raised in your program."

    Read the article

  • Exporting to XML, including embedded classes

    - by Andy
    I have an object config which has some properties. I can export this ok, however, it also has an ArrayList which relates to embedded classes which I can't get to appear when I export to XML. Any pointers would be helpful. Export Method public String exportXML(config conf, String path) { String success = ""; try { FileOutputStream fstream = new FileOutputStream(path); try { XMLEncoder ostream = new XMLEncoder(fstream); try { ostream.writeObject(conf); ostream.flush(); } finally { ostream.close(); } } finally { fstream.close(); } } catch (Exception ex) { success = ex.getLocalizedMessage(); } return success; } Config Class (some detail stripped to keep size down) public class config { protected String author = ""; protected String website = ""; private ArrayList questions = new ArrayList(); public config(){ } public void addQuestion(String name) { questions.add(new question(questions.size(), name)); } public void removeQuestion(int id) { questions.remove(id); for (int c = 0; c <= questions.size(); c++) { question q = (question) (questions.get(id)); q.setId(c); } questions.trimToSize(); } public config.question getQuestion(int id){ return (question)questions.get(id); } /** * There can be multiple questions per config. * Questions store all the information regarding what questions are * asked of the user, including images, descriptions, and answers. */ public class question { protected int id; protected String title; protected ArrayList answers; public question(int id, String title) { this.id = id; this.title = title; } public int getId() { return id; } public void setId(int id) { this.id = id; } public void addAnswer(String name) { answers.add(new answer(answers.size(), name)); } public void removeAnswer(int id) { answers.remove(id); for (int c = 0; c <= answers.size(); c++) { answer a = (answer) (answers.get(id)); a.setId(c); } answers.trimToSize(); } public config.question.answer getAnswer(int id){ return (answer)answers.get(id); } public class answer { protected int id; protected String title; public answer(int id, String title) { this.id = id; this.title = title; } public int getId() { return id; } public void setId(int id) { this.id = id; } } } } Resultant XML File <?xml version="1.0" encoding="UTF-8"?> <java version="1.6.0_18" class="java.beans.XMLDecoder"> <object class="libConfig.config"> <void property="appName"> <string>xxx</string> </void> <void property="author"> <string>Andy</string> </void> <void property="website"> <string>www.example.com/dsx.xml</string> </void> </object> </java>

    Read the article

  • Split a Large File In C++

    - by wdow88
    Hey all, I'm trying to write a program that takes a large file (of any time) and splits it into many smaller "chunks". I think I have the basic idea down, but for some reason I cannot create a chunk size over 12,000 bites. I know there are a few solutions on google, etc. but I am more interested in learning what the origin of this limitation is then actually using the program to split files. //This file splits are larger into smaller files of a user inputted size. #include<iostream> #include<fstream> #include<string> #include<sstream> #include <direct.h> #include <stdlib.h> using namespace std; void GetCurrentPath(char* buffer) { _getcwd(buffer, _MAX_PATH); } int main() { // use the function to get the path char CurrentPath[_MAX_PATH]; GetCurrentPath(CurrentPath);//Get the current directory (used for displaying output) fstream bigFile; string filename; int partsize; cout << "Enter a file name: "; cin >> filename; //Recieve target file cout << "Enter the number of bites in each smaller file: "; cin >> partsize; //Recieve volume size bigFile.open(filename.c_str(),ios::in | ios::binary); bigFile.seekg(0, ios::end); // position get-ptr 0 bytes from end int size = bigFile.tellg(); // get-ptr position is now same as file size bigFile.seekg(0, ios::beg); // position get-ptr 0 bytes from beginning for (int i = 0; i <= (size / partsize); i++) { //Build File Name string partname = filename; //The original filename string charnum; //archive number stringstream out; //stringstream object out, used to build the archive name out << "." << i; charnum = out.str(); partname.append(charnum); //put the part name together //Write new file part fstream filePart; filePart.open(partname.c_str(),ios::out | ios::binary); //Open new file with the name built above //Check if near the end of file if (bigFile.tellg() < (size - (size%partsize))) { filePart.write(reinterpret_cast<char *>(&bigFile),partsize); //Write the selected amount to the file filePart.close(); //close file bigFile.seekg(partsize, ios::cur); //move pointer to next position to be written } //Changes the size of the last volume because it is the end of the file else { filePart.write(reinterpret_cast<char *>(&bigFile),(size%partsize)); //Write the selected amount to the file filePart.close(); //close file } cout << "File " << CurrentPath << partname << " produced" << endl; //display the progress of the split } bigFile.close(); cout << "Split Complete." << endl; return 0; } Any ideas? Thanks!

    Read the article

  • How Can I Generate Equivalent Output Using the CryptoAPI and the .NET Encryption (TripleDESCryptoSer

    - by S. Butts
    I have some C#/.NET code that encrypts and decrypts data using TripleDES encryption. It sticks to the sample code provided at MSDN pretty closely. The encryption piece looks like the following: TripleDESCryptoServiceProvider _desProvider = new TripleDESCryptoServiceProvider(); //bytes for key and initialization vector //keyBytes is 24 bytes of stuff, vectorBytes is 8 bytes of stuff byte[] keyBytes; byte[] vectorBytes; FileStream fStream = File.Open(locationOfFile, FileMode.Create, FileAccess.Write); CryptoStream cStream = new CryptoStream(fStream, _desProvider.CreateEncryptor(keyBytes, vectorBytes), CryptoStreamMode.Write); BinaryWriter bWriter = new BinaryWriter(cStream); //write out encrypted data //raw data is a few bytes of binary information byte[] rawData; bWriter.Write(rawData); With encrypting and decrypting in C#, this all works like a charm. The problem is I need to write a small Win32 utility that will duplicate the encryption above. I have tried several methods using the CryptoAPI, and I simply do not get output that the .NET piece can decrypt, no matter what I do. Can someone please tell me what the equivalent C++ code is that will produce the same output? I am not certain just what methods of the CryptoAPI the .NET functions use to encrypt the data. What options are used, and what method of generating the key is used? Before someone suggests that I just write it in C# anyway, or create some common library bridge for them, those options are unfortunately off the table. It really has to work in Win32 with .NET and without using a DLL. I have some leeway in changing the C# code. I apologize in advance if this is bone-headed, as I am new to encryption.

    Read the article

  • Writing XML in different character encodings with Java

    - by Roman Myers
    I am attempting to write an XML library file that can be read again into my program. The file writer code is as follows: XMLBuilder builder = new XMLBuilder(); Document doc = builder.build(bookList); DOMImplementation impl = doc.getImplementation(); DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0"); LSSerializer ser = implLS.createLSSerializer(); String out = ser.writeToString(doc); //System.out.println(out); try{ FileWriter fstream = new FileWriter(location); BufferedWriter outwrite = new BufferedWriter(fstream); outwrite.write(out); outwrite.close(); }catch (Exception e){ } The above code does write an xml document. However, in the XML header, it is an attribute that the file is encoded in UTF-16. when i read in the file, i get the error: "content not allowed in prolog" this error does not occur when the encoding attribute is manually changed to UTF-8. I am trying to get the above code to write an XML document encoded in UTF-8, or successfully parse a UTF-16 file. the code for parsing in is DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder loader = factory.newDocumentBuilder(); Document document = loader.parse(filename); the last line returns the error.

    Read the article

  • Capture data read from file into string stream Java

    - by halluc1nati0n
    I'm coming from a C++ background, so be kind on my n00bish queries... I'd like to read data from an input file and store it in a stringstream. I can accomplish this in an easy way in C++ using stringstreams. I'm a bit lost trying to do the same in Java. Following is a crude code/way I've developed where I'm storing the data read line-by-line in a string array. I need to use a string stream to capture my data into (rather than use a string array).. Any help? char dataCharArray[] = new char[2]; int marker=0; String inputLine; String temp_to_write_data[] = new String[100]; // Now, read from output_x into stringstream FileInputStream fstream = new FileInputStream("output_" + dataCharArray[0]); // Convert our input stream to a BufferedReader BufferedReader in = new BufferedReader (new InputStreamReader(fstream)); // Continue to read lines while there are still some left to read while ((inputLine = in.readLine()) != null ) { // Print file line to screen // System.out.println (inputLine); temp_to_write_data[marker] = inputLine; marker++; }

    Read the article

  • Traceroute comparison and statistics

    - by ben-casey
    I have a number of traceroutes that i need to compare against each other but i dont know the best way to do it, ive been told that hash maps are a good technique but i dont know how to implement them on my code. so far i have: FileInputStream fstream = new FileInputStream("traceroute.log"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // reads lines in while ((strLine = br.readLine()) != null) { System.out.println(strLine); } and the output looks like this: Wed Mar 31 01:00:03 BST 2010 traceroute to www.bbc.co.uk (212.58.251.195), 30 hops max, 40 byte packets 1 139.222.0.1 (139.222.0.1) 0.873 ms 1.074 ms 1.162 ms 2 core-from-cmp.uea.ac.uk (10.0.0.1) 0.312 ms 0.350 ms 0.463 ms 3 ueaha1btm-from-uea1 (172.16.0.34) 0.791 ms 0.772 ms 1.238 ms 4 bound-from-ueahatop.uea.ac.uk (193.62.92.71) 5.094 ms 4.451 ms 4.441 ms 5 gi0-3.norw-rbr1.eastnet.ja.net (193.60.0.21) 4.426 ms 5.014 ms 4.389 ms 6 gi3-0-2.chel-rbr1.eastnet.ja.net (193.63.107.114) 6.055 ms 6.039 ms * 7 lond-sbr1.ja.net (146.97.40.45) 6.994 ms 7.493 ms 7.457 ms 8 so-6-0-0.lond-sbr4.ja.net (146.97.33.154) 8.206 ms 8.187 ms 8.234 ms 9 po1.lond-ban4.ja.net (146.97.35.110) 8.673 ms 6.294 ms 7.668 ms 10 bbc.lond-sbr4.ja.net (193.62.157.178) 6.303 ms 8.118 ms 8.107 ms 11 212.58.238.153 (212.58.238.153) 6.245 ms 8.066 ms 6.541 ms 12 212.58.239.62 (212.58.239.62) 7.023 ms 8.419 ms 7.068 ms what i need to do is compare this trace against another one just like it and look for the changes and time differences etc, then print a stats page.

    Read the article

  • Reference to the Main Form whilst trying to Serialize objects in C#

    - by Paul Matthews
    I have a button on my main form which calls a method to serialize some objects to disk. I am trying to add these objects to an ArrayList and then serialize them using a BinaryFormatter and a FileStream. public void SerializeGAToDisk(string GenAlgName) { // Let's make a list that includes all the objects we // need to store a GA instance ArrayList GAContents = new ArrayList(); GAContents.Add(GenAlgInstances[GenAlgName]); // Structure and info for a GA GAContents.Add(RunningGAs[GenAlgName]); // There may be several running GA's using (FileStream fStream = new FileStream(GenAlgName + ".ga", FileMode.Create, FileAccess.Write, FileShare.None)) { BinaryFormatter binFormat = new BinaryFormatter(); binFormat.Serialize(fStream, GAContents); } } When running the above code I get the following exception: System.Runtime.Serialization.SerializationException was unhandled Message=Type 'WindowsFormsApplication1.Form1' in Assembly 'GeneticAlgApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. So that means that somewhere in the objects I'm trying to save there must be a reference to the main form. The only possible references I can see are 3 delegates which all point to methods in the main form code. Do delegates get serialized as well? I can't seem to apply the [NonSerialized] attribute to them. Is there anything else I might be missing? Even better, is there a quick method to find the reference(s) that are causing the problem?

    Read the article

  • How does does ifstream eof() work?

    - by Chan
    Hello everyone, #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cctype> #include <fstream> using namespace std; int main() { fstream inf( "ex.txt", ios::in ); while( !inf.eof() ) { std::cout << inf.get() << "\n"; } inf.close(); inf.clear(); inf.open( "ex.txt", ios::in ); char c; while( inf >> c ) { std::cout << c << "\n"; } return 0; } I'm really confused about eof() function. Suppose my ex.txt's content is: abc It always reads an extra character and show -1. when reading using eof()? But the inf c gave the correct output which was 'abc'? Can anyone help me explain this? Best regards, Chan Nguyen

    Read the article

  • How to update coffee script?

    - by Tetsu
    I got a following error when I tried to watch coffee scripts by coffee -o js -cw coffee. /usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:321 throw e; ^ Error: watch Unknown system errno 28 at errnoException (fs.js:636:11) at FSWatcher.start (fs.js:663:11) at Object.watch (fs.js:691:11) at /usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:287:27 at Object.oncomplete (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:100:11) I have no idea what is going with error. Then I checked the versions, coffee -v is 1.6.1 and node -v is v0.6.12. According the official site( http://coffeescript.org/ ) the latest version is 1.6.3, so I wanted update coffee by npm update -g coffee-script, but this fails also. npm WARN [email protected] package.json: bugs['name'] should probably be bugs['url'] npm http GET https://registry.npmjs.org/coffee-script npm http 304 https://registry.npmjs.org/coffee-script How can I update coffee script? Edit 2013/10/11 In my coffee script directory there is only one file box_wrapper.coffee. $ -> $("body").children().wrap -> "<div id='#{$(@).attr "id"}_box' class='wrapper'/>" Edit 2013/10/16 I tried to re-install coffee, so I've done like this. $ sudo npm -g rm coffee npm WARN Not installed in /usr/local/lib/node_modules coffee $ coffee -v CoffeeScript version 1.6.1 I can't remove coffee. And I tried also like this. $ sudo apt-get remove npm $ npm -v -bash: /usr/bin/npm: No such file or directory $ sudo apt-get install npm $ npm -v 1.1.4 $ sudo npm -g install coffee # I omit a lot of `GET` parts. npm http 304 https://registry.npmjs.org/mkdirp/0.3.4 npm ERR! error installing [email protected] npm http 304 https://registry.npmjs.org/assertion-error/1.0.0 npm http 304 https://registry.npmjs.org/growl npm http 304 https://registry.npmjs.org/jade/0.26.3 npm http 304 https://registry.npmjs.org/diff/1.0.2 npm http 304 https://registry.npmjs.org/mkdirp/0.3.5 npm http 304 https://registry.npmjs.org/glob/3.2.1 npm http 304 https://registry.npmjs.org/ms/0.3.0 npm ERR! error rolling back [email protected] Error: UNKNOWN, unknown error '/usr/local/lib/node_modules/coffee/node_modules/express' npm ERR! error installing [email protected] npm ERR! EEXIST, file already exists '/usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules' npm ERR! File exists: /usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules npm ERR! Move it away, and try again. npm ERR! npm ERR! System Linux 3.2.0-54-generic-pae npm ERR! command "node" "/usr/bin/npm" "-g" "install" "coffee" npm ERR! cwd /home/ironsand npm ERR! node -v v0.6.12 npm ERR! npm -v 1.1.4 npm ERR! path /usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules npm ERR! fstream_path /usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules/___debug.npm npm ERR! fstream_type Directory npm ERR! fstream_class DirWriter npm ERR! code EEXIST npm ERR! message EEXIST, file already exists '/usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules' npm ERR! errno {} npm ERR! fstream_stack /usr/lib/nodejs/fstream/lib/writer.js:161:23 npm ERR! fstream_stack Object.oncomplete (/usr/lib/nodejs/mkdirp.js:34:53) npm ERR! EEXIST, file already exists '/usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules' npm ERR! File exists: /usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules npm ERR! Move it away, and try again. npm ERR! npm ERR! System Linux 3.2.0-54-generic-pae npm ERR! command "node" "/usr/bin/npm" "-g" "install" "coffee" npm ERR! cwd /home/ironsand npm ERR! node -v v0.6.12 npm ERR! npm -v 1.1.4 npm ERR! path /usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules npm ERR! fstream_path /usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules/___debug.npm npm ERR! fstream_type Directory npm ERR! fstream_class DirWriter npm ERR! code EEXIST npm ERR! message EEXIST, file already exists '/usr/local/lib/node_modules/coffee/node_modules/mocha/node_modules' npm ERR! errno {} npm ERR! fstream_stack /usr/lib/nodejs/fstream/lib/writer.js:161:23 npm ERR! fstream_stack Object.oncomplete (/usr/lib/nodejs/mkdirp.js:34:53) npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /home/ironsand/npm-debug.log npm not ok And npm-debug.log is a blank file.

    Read the article

  • What is wrong with this code for reading binary files? [on hold]

    - by qed
    What is wrong with this code for reading binary files? It compiles OK, but will not print out the file as planned, in fact, it prints nothing at all. #include <iostream> #include <fstream> int main(int argc, const char *argv[]) { if (argc < 2) { ::std::cerr << "usage: " << argv[0] << " <filename>\n"; return 1; } ::std::basic_ifstream<unsigned char> in(argv[1], ::std::ios::binary); unsigned char uc; while (in.get(uc)) { printf("%02X ", uc); } // TODO: error handling, in case the file could not be opened or read return 0; }

    Read the article

  • GetPrivateProfileString funtion for MFC application in Win CE

    - by ame
    I understand that WinCE does not support the above function. However as it has been used in the code I am trying to port to Win CE environment, I am trying to rewrite the function to work in Win CE. http://www.codeproject.com/KB/mobile/GetPrivateProfileString.aspx The code at this link does not work as fstream is not supported. Please let me know how I can modify the above code/ rewrite the code for my purpose.

    Read the article

  • Reading a file with a supplied name in C++

    - by Cosmina
    I must read a file with a given name (it's caled "hamlet.txt"). The class used to read the file is defined like this #ifndef READWORDS_H #define READWORDS_H /** * ReadWords class. Provides mechanisms to read a text file, and return * capitalized words from that file. */ using namespace std; #include <string> #include <fstream> class ReadWords { public: /** * Constructor. Opens the file with the default name "text.txt". * Program exits with an error message if the file does not exist. */ ReadWords(); /** * Constructor. Opens the file with the given filename. * Program exits with an error message if the file does not exist. * @param filename - a C string naming the file to read. */ ReadWords(char *filename); My definition of the members of the classis this: #include<string> #include<fstream> #include<iostream> #include "ReadWords.h" using namespace std; ReadWords::ReadWords() { wordfile.open("text.txt"); if( !wordfile ) { cout<<"Errors while opening the file!"<<endl; } } ReadWords::ReadWords(char *filename) { wordfile.open(filename); if ( !wordfile ) { cout<<"Errors while opening the file!"<<endl; } wordfile>>nextword; } And the main to test it. using namespace std; #include #include #include "ReadWords.h" int main() { char name[30]; cout<<"Please input a name for the file that you wish to open"; cin>>name; ReadWords x( name[] ); } When I complie it gives me the error: main.cpp:14: error: expected primary-expression before ']' token I know it's got something to do with the function ReadWords( char *filename), but I do not know what. Any help please?

    Read the article

  • How to display specific data from a file

    - by user1067332
    My program is supposed to ask the user for firstname, lastname, and phone number till the users stops. Then when to display it asks for the first name and does a search in the text file to find all info with the same first name and display lastname and phones of the matches. import java.util.*; import java.io.*; import java.util.Scanner; public class WritePhoneList { public static void main(String[] args)throws IOException { BufferedWriter output = new BufferedWriter(new FileWriter(new File( "PhoneFile.txt"), true)); String name, lname, age; int pos,choice; try { do { Scanner input = new Scanner(System.in); System.out.print("Enter First name, last name, and phone number "); name = input.nextLine(); output.write(name); output.newLine(); System.out.print("Would you like to add another? yes(1)/no(2)"); choice = input.nextInt(); }while(choice == 1); output.close(); } catch(Exception e) { System.out.println("Message: " + e); } } } Here is the display code, when i search for a name, it finds a match but displays the last name and phone number of the same name 3 times, I want it to display all of the possible matches with the first name. import java.util.*; import java.io.*; import java.util.Scanner; public class DisplaySelectedNumbers { public static void main(String[] args)throws IOException { String name; String strLine; try { FileInputStream fstream = new FileInputStream("PhoneFile.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); Scanner input = new Scanner(System.in); System.out.print("Enter a first name"); name = input.nextLine(); strLine= br.readLine(); String[] line = strLine.split(" "); String part1 = line[0]; String part2 = line[1]; String part3 = line[2]; //Read File Line By Line while ((strLine= br.readLine()) != null) { if(name.equals(part1)) { // Print the content on the console System.out.print("\n" + part2 + " " + part3); } } }catch (Exception e) {//Catch exception if any System.out.println("Error: " + e.getMessage()); } } }

    Read the article

  • Java's getResourceAsStream() is always returning null

    - by Andreas Grech
    I have the following structure in a Java Web Application: TheProject -- [Web Pages] -- -- [WEB-INF] -- -- -- abc.txt -- -- index.jsp -- [Source Packages] -- -- [wservices] -- -- -- WS.java In WS.java, I am using the following code in a Web Method: InputStream fstream = this.getClass().getResourceAsStream("abc.txt"); But it is always returning a null. I need to read from that file, and I read that if you put the files in WEB-INF, you can access them with getResourceAsStream, yet the method is always returning a null. Any ideas of what I may be doing wrong?

    Read the article

  • converting array of bytes to UTF-8 unicode

    - by user394242
    I have a file saved as UTF-8, and i'm reading it like this: ReadFile(hFile, pContents, pFile->nFileSize, &dwRead, NULL); (pContents is a BYTE* of size nFileSize) its just a small file with 100 bytes or so, contains text which i want to read into memory in wchar_t* format, so i can set the text of edit and static controls with the unicode text. How can i convert the bytes to UTF-8? edit (i don't want to use fstream or wfstream)

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >