Curiosity, learning and homework help
21/12/2024
Sign upLog in
Language: FR | ENG

> Back to the home page <

Discussion forums

[Visual Studio] [C++] [Fortran] Writing ouput C++/Fortran
You have to be logged in to reply
Author Message
ExaSec56

Member
Posted on 30/11/2021 at 14:33:44

by ExaSec56
Member
Hello,

I am building a project in C++/Fortran and I am using Visual Studio. However, I am facing an issue. When I try to print a value either in C++ or in Fortran, the value is printed on the console of Visual Studio but the console is quickly closed automatically after opening so I cannot see anything.

For example, when I do this in C++:
std::cout << "text to print" << std::endl;

I cannot see the printed text since the console does not stay open.

Is it possible to redirect all outputs from Visual Studio to somewhere else or a file instead of printed them on the console without changing the code?
Thank you.
TheLibrarian

**Moderator**
Posted on 30/11/2021 at 19:05:05

by TheLibrarian
**Moderator**
Hello ExaSec! 🙂

To redirect all standard outputs to a text file in Visual Studio without changing your code, you can modify the properties of your Visual Studio project.

You can do the following:
  • right-click on your project
  • go to Properties
  • go to Debugging in the left panel
  • add an instruction in the "Command Arguments" field

For example, you can add
> test.txt

to redirect all standard outputs to a file named "test.txt" which will be created if it does not already exist or overwritten if it already exists.

You can of course do the same for the standard errors.

I hope it helps.
--------------------------
ExaSec56

Member
Posted on 30/11/2021 at 19:33:22

by ExaSec56
Member
Yes, it works. It is good to know.
You saved me a lot of time. Thank you!
You have to be logged in to reply
Share this page on social media:

Use of cookies on this website:
- If you are not a member of this website, no cookie is intentionally stored on your computer.
- If you are a member of this website, cookies are only used to keep your connection after each visit. This option can be deactivated at will in your profile and is deactivated by default.
- No other information is stored or retrieved without your knowledge, neither your personal information nor any other whatsoever. If in doubt, do not hesitate to contact the administrator of this website .
- Even this information banner does not use cookies and will therefore be displayed constantly on each visit on all pages of the website.