How to read file with n object in c++?

I have problem with binary file when I try to read data, but it doesn't return anything. In this code I write 'n' objects of class worker, and then I want to read in 'n' objects and have them write themselves to the screen.

void show() { ifstream f("worker.bin",ios::binary); worker *p; int n; f.seekg(0, f.end); n = f.tellg() / sizeof(int); p = new worker[n]; cout << "n:" << n; f.seekg(0, ios::beg); f.read((char*)&p, n * sizeof(worker)); f.close(); for(int i = 0; i < n; i++) { p[i].output(); cout << endl; } }

Category:c# Views:13 Time:2018-12-19
Tags:

Related post

  • How to read file with custom extension to textBox 2011-08-09

    Is there any way to read file with custom extension to textBox? Is there any convertation to some supported formats? I need read file with custom extension, like text.blahblahblah. --------------Solutions------------- Is there any way to read file wi

  • How to read file with no-cache in Android? 2010-11-16

    I am working on a test application on Android platform. Test the write/read speed to the sdcard. I write in C language with NDK interface. First I write a for-loop to create 256 files with 512 random bytes in each. This part works fine. I open file w

  • Python - how to read file with NUL delimited lines? 2012-02-11

    I usually use the following Python code to read lines from a file : f = open('./my.csv', 'r') for line in f: print line But how about if the file is line delimited by "" (not "\n") ? Is there a Python module that could handle this ? Thanks for any ad

  • How to read files with different encodings using Awk? 2009-11-30

    How can I correctly read files in encodings other than UTF8 in Awk? I have a file in Hebrew/Windows-1255 encoding. A simple {print $0} awk prints stuff like �. how can I make it read correctly? --------------Solutions------------- awk itself doesn't

  • how to read files with spaces and special characters in their name? 2010-09-29

    i have lots of videos in my server and i use the following code to get the duration of the video and it works fine.. ob_start(); passthru("ffmpeg -i ".$srcfile." 2>&1"); $duration = ob_get_contents(); ob_end_clean(); But i could not get the du

  • how to read file with multiple record 2011-10-07

    this is similiar to my previous question: but here is some improvisation: 3 4 5 aaaaa aaaaa aaaaa aaaaa bbbbb bbbbb bbbbb bbbbb ccccc ccccc ccccc ccccc 1 2 3 aaa aaa the first number is the level, the second is the row and the third is the column, i

  • How to read file outside of www directory 2011-04-10

    How to read file with php when that file is outside my site ( www or htdocs ) directory but is on server ? --------------Solutions------------- Just specify the full path (such as /var/www/whatever) or use relative paths. (../ means the directory rig

  • how to read file from client system with java? I have to use wsdl? 2009-09-15

    I want to read file from client system, I have path of client system where our file is generated, I want to use WSDL to do this functionality ... I am new to WSDL if any body already did please guide me how to read file from client system with WSDL .

  • how to read files of a directory? 2011-05-16

    FM = [NSFileManager defaultManager]; directoryContents = [FM contentsOfDirectoryAtPath:@"/Users/myComputer/Library/Application Support/iPhone Simulator/4.3/Applications/CD88649C-E545-4E10-84DF-F4E5D829641B/Documents" error:NULL]; but it gives me obje

  • How to create File with the FILE_ATTRIBUTE_TEMPORARY in C#? 2010-05-30

    How to create File with the FILE_ATTRIBUTE_TEMPORARY in C#? (So to store Data in Ram but be able to use it as normal file) --------------Solutions------------- I believe you'll have to use P/Invoke to call the native CreateFile then use the FileStrea

  • Can I tell Visual Studio how treat a file with a custom file extension? 2010-08-16

    Can I tell Visual Studio how treat a file with a custom file extension? I want to be able to open a file with ".xxx" extension in Visual Studio and have CSS highlighting. I've tried to do it by going to VS -> Tools -> Options -> Text Editor

  • How To Read Files From HTTP POST 2010-10-01

    How to read files (zip and xml formats) that are delivered to web server from a client application via HTTP POST using java --------------Solutions------------- commons-fileupload is a library to use on the server to read uploaded files. Read the use

  • How garbage collection works with Session object in Java? 2011-03-14

    How garbage collection works with Session object in JSP? Whether each session gets garbage collected after session gets expired? What is better way to handle memory with Session objects in JSP? --------------Solutions------------- The garbage collect

  • How download cvs file with google authorization in google insights - have to use zend classes and not other php ways (zend_gbase etc.. ) 2011-06-15

    How download cvs file with google authorization in google trends service - have to use zend framework classes and not other php ways . Thanks, Yosef --------------Solutions------------- This could be what you need. You need to enter your Google usern

  • How to read file(bigger) in php from bottom up 2011-07-12

    How to read files from bottom up in php?Is there something like stream in java which will read file incrementally but just backwards. Because my files can get up to 650 mb. --------------Solutions------------- PHP has streams. See: http://php.net/man

  • How to read file in J2ME using getResourceAsStream 2011-10-09

    My J2ME program structure is like as follow. File Read -src -res -test -abc.txt -java libraries Here abc.txt is in test folder Now I am reading file as follow: InputStream is = getClass().getResourceAsStream("test/abc.txt"); after executing above sta

  • How to read file and send to other URL 2012-03-21

    How to read file from file system and send that to another URL ? Its similar to CURL request which we use in other languages. I have tried following, but that is not working. fs.createReadStream(files.upload.path).pipe(request.post('http://localhost/

  • Can't print READER files with my Kodak ESP 7250 printer. 2012-11-25

    I've been unable to print READER files with my Kodak ESP 7250 printer. pdf files will not print regardless of whether the source is READER or Adobe. Have downloaded the latest print drivers with no change in condition. The printer will print other fi

  • How to search File with name as part like i have testMyFile123.xml I wanted to search it via MyFile in search box 2013-02-24

    How to search File with name as part like i have testMyFile123.xml , 123MyFileA3423.xml I wanted to search it via MyFile in search box --------------Solutions------------- Do it like you would in Windows XP or such: to find it, try typing this: *myfi

  • How to rename files with specific extension using pig or hadoop fs option? 2014-02-20

    I have *.gz files in mm/dd/yyyy partition based folder structure . I want to rename files which ends with .gz extension. Please suggest how to rename files with specific extension using hadoop fs command line option or using pig. here is my folder st

  • how to delete files with dll extension? 2014-04-05

    How to delete files with extension dll? --------------Solutions------------- Where do the files reside? Why do you want to delete them? The same way you delete any file, but of course if that file is in use you cannot delete it, and if the file is us

  • How to read float with scientific notation from file C++? 2012-01-24

    I have a file with this format: -0.0064785667 0.73900002 0.028505694 4.7858757e-39 315 218 -0.0051828534 0.73900002 0.028505694 4.6936954e-39 316 218 -0.0038818798 0.73799998 0.028467119 5.1546736e-39 317 218 -0.0025879198 0.73799998 0.028467119 5.61

  • How to open a file with .ocf (Object Craft File)extension 2012-04-03

    i need to open a file with .ocf extension .ocf stands for object craft file it is a ebook format suggest me a program to open this type of document --------------Solutions------------- an Object Craft File that is particularly used by Microsoft Windo

  • how to read jquery ajax returned object with out a loop 2011-09-13

    Given the following jquery ajax request: $.getJSON("getSearchSystems.php", {level: "full", data:this.label}, function(data){ //This method does not work. console.log(data.regionName); console.log(data.constellationName); console.log(data.solarSystemN

  • How to read file from phone's internal memory in android? 2010-02-04

    I have downloaded a file from HttpConnection using the FileOutputStream in android and now its being written in phone's internal memory on path as i found it in File Explorer /data/data/com.example.packagename/files/123.ics Now, I want to open &

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

processed in 0.209 (s). 11 q(s)