Opening, writing, then running a file.

Pages: 12
How do i create a file, open it to writ to, and then run it. (like a batch file etc.) I looked at the tutorial, but i still dont understand the syntax.
Last edited on
tjyuyujyu
hmm
Randomly bumping your post every few minutes will not help you any. If you show a little more patient and give a little more insight to what you mean, you'll get more help.

With that said, what are you talking about? Do you want to write a program that will write to a batch file and then run the batch file?
1- wow you noticed?

2- well, yes. I wrote this exact program useing BASIC language and i want to excercise my C++ my replicating it. With that said, i have the input/output form the user, i just need to correctly write the code to open/create the file, write to it, close the file, then execute the file, and lastly delete the file so that we dont (after say, 10 uses) have a bucket load of batch files sitting around. Only thing is, im not quite sure i understand the syntax of the "open/close" statements or how to use them. Mabey an example and an explanation would help me out. Thank you for your time!
Last edited on
How do you run a file? How do you delete it?
Last edited on
... is there a place i can get an index with definitions of every statement there is to know in C++?
Well you have to learn File I/O (if i am right about your question). Here is an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <fstream>


using namespace std;

int main(){
    
    char filename[MAX_PATH + 1];
    char input_line[MAX_PATH + 1];
    
    cout << "Input a file path and name and press ENTER: ";
    cin.getline(filename, MAX_PATH);
    
    ofstream myfile(filename);
    
    
    cout << " Input text: ";
    cin.getline(input_line, MAX_PATH);
    
    myfile << input_line << endl;
    
    myfile.close();
    
    
    
    system("PAUSE");
    return 0;
}
yes, i already solved that.... I got it to create the files, not i just need it to run them and delete them.

what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you.
OK, LOOK. THIS POST HAS BEEN UP ALL WEEK, I WOULD REEEEEEEAAAAALLLLLLYYY APPRECIATE IT IF SOMEONE COULD HELP ME...
Being demanding like that won't encourage anyone to help you.
Besides, it hasn't even been 48 hours, yet.
what? yes it has, dude, it's been 5 entire days. I've been re-posting the last post to bump it up (after being completely knocked off the page) in hopes of my questiong being answered by someone.
what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you. what is the statement that specifies and runs a file? What is the statement that deletes a file? I would apprecciate this, thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <fstream>


using namespace std;

int main(){
    
    char filename[MAX_PATH + 1];
    char input_line[MAX_PATH + 1];
    
    cout << "Input a file path and name and press ENTER: ";
    cin.getline(filename, MAX_PATH);
    
    ifstream myfile(filename);
    
    if(!myfile){
     system("PAUSE");
return -1;
}
 
  myfile.getline(input_line, MAX_PATH);
  
cout << input_line << endl; 
    
    
    
    
    myfile.close();
    
    
    
    system("PAUSE");
    return 0;
}



?? Sorry i am confused because of this " I got it to create the files, not i just need it to run them and delete them." ?! Okay i think it is this 0.o.
ok... what's the "run" statement in that? I can't just write jibberish i don't understand... Explain to me how this works please. Sorry if i come up a bit obnoxious, i just cant find an answer to this question. Thank you for your time.
There is no "run" statement, in the case of happykillers example the content of the file can be used as input for the program.

ifstream allows you to input data from a file
so... if i want it to run a batch program, it wouldnt work?
No it would not

system(filename) might be what you are looking for I'm not sure what you are asking tho
let me clarify:

when a program is active, we say it is "running", yes?
How do i make my program "run" a batch file??? I'm not quite sure how you can make a virus with C++, but you can't MERELY run a simple batch file...
The BASIC language allows you to run a file, so why not C++??????????????!?!
Last edited on
and BTW SYSTEM DOESNT WORK, like SYSTEM(ANYTHING) doesnt work. why do people keep mentioning this statement, it isnt even recognized by the compiler.
Last edited on
Pages: 12