Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. C++ Binary File Modifying

C++ Binary File Modifying

Scheduled Pinned Locked Moved Managed C++/CLI
c++iosdata-structureshelp
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12001697
    wrote on last edited by
    #1

    Hi guys I was trying to write some data in binary file and then display it. Everything works good but I tried to add one more options which is modify the data by using item id but I couldn't finish it can you guys show my mistake in my code thank you fstream binaryFile("Inventory.dat", ios::in | ios::out | ios::binary); Inventory obj; int userInput; cin >> userInput; while (binaryFile.read((char*)&obj, sizeof(obj))) { if (userInput = *obj.itemId) { cout << "Enter item description :: " << flush; cin.getline(obj.description, DESCRIPTION_LENGTH); // Character Array Getline while (!isValidInput(obj.quantity, 0, INT_MAX, "Enter quantity on hand :: >> ", "Error: number must be greater than 0")); while (!isValidInput(obj.wholeSalePrice, 0.0, DBL_MAX, "Enter whole sale price :: >> ", "Error: number must be greater than 0")); while (!isValidInput(obj.retailPrice, 0.0, DBL_MAX, "Enter retail price :: >> ", "Error: number must be greater than 0")); cin.ignore(INT_MAX, '\n'); cout << "Enter date added (MM/DD/YYYY) :: " << flush; cin.getline(obj.dataAdded, DATE_LENGTH); cout << "Enter item id (max 5 digit ) :: " << flush; cin.getline(obj.itemId, ITEM_ID_LENGTH); int pos = -1 * sizeof(obj); binaryFile.seekp(pos, ios::cur); binaryFile.write((char*)&obj, sizeof(obj)); } } binaryFile.close(); }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups