Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6729057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:14:36+00:00 2026-05-26T10:14:36+00:00

So im writing c++ program, that takes a integer from input file, multiply it

  • 0

So im writing c++ program, that takes a integer from input file, multiply it with 2 and outputs it on output file. So the code is –

#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
    int n;
    FILE * inFile;
    FILE * outFile;
    inFile = fopen ("reiz.in","r");
    outFile = fopen ("reiz.out","r+");
    fscanf (inFile, "%s", n);
    int m = n * 2;
    fprintf (outFile, "%n", n);
    fclose (inFile);
    fclose (outFile);
    return 0;
}

But something is wrong. in reiz.in file there is number 2, after running program it should output 4 in reiz.out, but it just shows don’t send error. What exactly is wrong with my script?
Best regards,
Y2oK

EDIT 1: Ok now it looks like this –

#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
    int n;
    FILE * inFile;
    FILE * outFile;
    inFile = fopen ("reiz.in","r");
    outFile = fopen ("reiz.out","r+");
    fscanf (inFile, "%d", &n);
    int m = n * 2;
    fprintf (outFile, "%d", m);
    fclose (inFile);
    fclose (outFile);
    return 0;
}

but still it gives same don’t send error when running reiz.exe file, and it doesn’t write anything on output file
I’m now a little bit confused, and don’t know who to chose as best answer, so I will chose the one who got most “+1”. But thanks to all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:14:37+00:00Added an answer on May 26, 2026 at 10:14 am

    This a C-program (apart from the using namespace std;). In C++ you should use streams and formatted I/O, like this:

    #include <fstream>
    
    int main() {
        std::ifstream input_file("reiz.in");
        int n;
        input_file >> n; // read one integer
        std::ostream output_file("reis.out");
        output_file << n * 2 << std::endl; // calculate n * 2 and write the result
                                           // to a file. std::endl adds a newline and
                                           // flushes the buffer
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program that takes in an input file from the user.
Looking for help on writing a Perl program that takes an input file and
I am writing a program that takes a file and splits it up into
I'm writing a tiny program that takes user input using Getops, and based on
I am writing a program that takes in a CSV file and makes a
Im writing a program that should read input via stdin, so I have the
If you are writing a program that is executable from the command line, you
I am writing a program that takes letters and converts them to telephone numbers.
I've got a GUI C++ program that takes a shell command from the user,
I'm writing a piece of client-side javascript code that takes a function and finds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.