0
Output everything in Function Main
Guys, if I have a simple program that combines two numbers after i collect them, I want to get out everything that's written inside the main function? Is there an idea for this or a code solution
12 Respuestas
+ 1
As I understand...you'r looking output to the console the contents of your cpp file.
This output everything in the file...it's up to to to find a way to navigate to the "main" function and print everything after, I don't know enough to help you with that.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
string myText;
ifstream myinput("main.cpp"); // <-change the filename here, my working file was "main.cpp".
while (getline (myinput, myText))
cout << myText << endl;
return 0;
}
+ 4
Hannah Chris I already answered, you can't do that. If I understand right, you want to add to the main function, while it is being executed, which is not possible.
+ 2
Question unclear. What do you mean ? Share the code please.
+ 2
1. Can you link your code ? I don't know what it is you want to put inside the main function, so a code is needed.
2. Don't add unecessary tags in your post, only keep the ones that are relevant: C++ main-function
+ 2
You have mentioned 2 programming languages: C++ and python. Without having your current code shared here, we cannot help you. It sounds a bit as if it's your homework?
+ 2
Hannah Chris what do you mean by "add to the main function" ? You can't output something in the main function, the output is always in a consone. Even if you rewrite the file, you can't recompile it and run it as the original one, if you get what I mean.
+ 2
1-It's not my homework
2- I'm Studying Python to find a job and c++ to solve problems
+ 2
When i run the program it does all what it should do. The only thing you can improvr is to include a sequence for ‚new line‘:
cout <<"\nthanks to you ";
But it‘s still not clear what you exactly expect. May be you can wtite a sample what the output should looks like?
+ 1
Click this link...It can explain it better that I can...
http://www.cplusplus.com/doc/tutorial/files/
0
The idea is, I want to print everything in the main function with all its variables and values, as if it were self-printed
0
rodwynnejones You did it, my expert friend
Can you explain your code to me