Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help in simple file input output program
#1
The program adds, display, edit aand deletes records from a binary file.
Well the compiler shuts down as soon as I run the program https://www.sendspace.com/file/nfy3h9

Can someone tell me why it ain't working and fix the error? Need for school assignment. Yelp! asap
...............
Reply
Thanks given by:
#2
(12-08-2016, 01:43 PM)davis60 Wrote:  Well the compiler shuts down as soon as I run the program https://www.sendspace.com/file/nfy3h9
The compiler is what translates the C++-code into what can actually run on your computer. Either the compiler shuts down when you try to compile the program, or the program shuts down when you try to run it.
Compiling the program does not run it. Do you have a .exe file you can run after compiling? Do you get an error message? Which compiler are you using? (an old one
#include<fstream.h>
hasn't been a thing since you were born)
Age ratings for movies and games (and similar) have never been a good idea.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.
Reply
Thanks given by:
#3
Well I didn't tried compiling it, I just ran it and got frustrated. The compiled exe never works in windows 10. So I haven't done it in a while.

Using turbo c++, in dos box. Like I said school assignment , and was asked to do in that.
Offtopic but I live in a rural area, and teachers here or in our country quite dont update.
...............
Reply
Thanks given by:
#4
Well, so running the code I found a few errors listed here in the order of chance to be what causes the program to fail to compile:
  1. emp.eof()
    should probably be
    empfile.eof()
    .
  2. cout<
    should probably be
    cout<<
    .
  3. goto
    -statements end with a
    ;
    not a
    :
    .
  4. int *get_code()
    should probably be
    int get_code()
    .
  5. main
    is supposed to return
    int
    .
  6. Initialization of
    ofstream o;
    is skipped, when jumping to
    case 5:
    . (add
    {
    after
    case 4:
    , and
    }
    before
    case 5:
    )
  7. using namespace std;
    to drag whatever is in the headers into the global namespace.
  8. ios::noreplace
    isn't a thing anymore, same thing goes for
    clrscr()
    and
    sleep()
    .
  9. #include <iostream>
    and
    #include <fstream>
    , instead of
    #include <fstream.h>
    .
On top of that I also got a few warnings:
  1. nc=emp.get_code()
    should probably be
    nc==emp.get_code()
    .
  2. gets
    is super unsafe (what happens if the user enters more characters than you have in your buffer?). Consider using
    fgets
    or
    getline
    [/codei]).
  3. empfile.seekp(empfile.tellg() - sizeof(emp)
    is ambiguous. Cast
    sizeof(emp)
    to
    streamlen
    (probably safe to ignore, and Turbo C++ might not support
    streamlen
    ).

Lastly, please find some way to rate whoever is teaching you as lowly as possible, because using Turbo C++ in a world where GCC, and Clang exist is plain and simply unacceptable.

(also consider deleting this thread to remove the evidence of you asking for help, if this works)
Age ratings for movies and games (and similar) have never been a good idea.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.
Reply
Thanks given by: MangaD , InPhiKnight , A-Man
#5
Oh well thanks, Made hella mistakes. Wrote that few hrs ago. My mistake of putting things for last moment. Gonna try to fix them as soon as I get out.

Well I cant change the people here, they just wont change! Cant wait to get out of this place after graduation.

There is 0.00 probability that someone gonna find this thread from my town lol

@Someone else Thank you so much for helping me at the last moment, I made the program work after a few more fixes.
What is "using namespace std ;" ?
...............
Reply
Thanks given by:
#6
Quote:What is "using namespace std ;" ?
That expands declarations in a namespace called "std" to the current scope.

Imagine you're talking with your friends about Bamboori being a good person and having a nice beard ..etc. It turns out there's a girl in your class with the name Bamboori, and your classmates think you're talking about this girl (oops). Now you talk a lot about Bamboori in your class, and now you have 2 options to clarify. Either you always say "LFE's Bamboori" - like "LFE's Bamboori burns pizza"  and "LFE's Bamboori has a cool beard" -, or you just make it clear to everybody that whenever you say any name of a user that's on LFE, you're referring to that person on LFE and not to a person in your school. After that, you can always just say "Bamboori burns pizza" and everybody would understand you're referring to LFE's. You basically told them you'll be
using namespace LFE
.

Similarly, you can tell us on LFE about the girl in your class called Bamboori either by referring to her as "MySchool's Bamboori" (or easier maybe, just write
MySchool::Bamboori
), or you tell us I'm
using namespace MySchool
and we'll understand that whenever you say Bamboori afterwards that you're referring to the girl in your school.

    C++-Code:
namespace LFE
{
  int Bamboori = 18947;
  int A_Man = 12821;
  int STM = 14145; 
  // etc..
};
 
namespace MySchool
{
  int Bamboori = 1738415;
  int Jack = 12491271;
  // etc..
};
 
MySchool::Bamboori += 2; // give her 2 things
LFE::Bamboori -= 3; // take 3 things
 
using namespace LFE; // right now, we're talking about LFE
 
Bamboori -= 5; // take 5 things from Bamboori
MySchool::Bamboori // give 5 things to your school's Bamboori


Now
cout
is an object put inside a namespace called "std" together with many other. You're free to declare
using namespace std;
, or to be safe from ambiguity in case there's some other object called "cout", you can just refer to
std::cout
everywhere. Doing the latter is good practice.
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by: AmadisLFE , InPhiKnight , sadbhav




Users browsing this thread: 2 Guest(s)