473,503 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using external files throughout a program (please read before replying)

I've got a program that uses functions to various tasks easily. How can I
initalize input and output files outside of the main program?
Sep 13 '05 #1
3 1177
deanfamily11 wrote:
I've got a program that uses functions to various tasks easily. How can I
initalize input and output files outside of the main program?


Not sure what you mean. Do you mean this?:

#include <iostream>
#include <fstream>

std::ifstream inputFile("input.txt");
std::ofstream outputFile("output.txt");

int main()
{
std::cout << "Files have been initialized outside main." <<
std::endl;
return 0;
}
:)
-shez-

Sep 13 '05 #2
Shezan Baig wrote:
deanfamily11 wrote:
I've got a program that uses functions to various tasks easily. How can I
initalize input and output files outside of the main program?

Not sure what you mean. Do you mean this?:

#include <iostream>
#include <fstream>

std::ifstream inputFile("input.txt");
std::ofstream outputFile("output.txt");

int main()
{
std::cout << "Files have been initialized outside main." <<
std::endl;
return 0;
}


Or maybe this

int main()
{
function1();
function2();
return 0;
}

void function1()
{
std::ifstream inputFile("input1.txt");
std::ofstream outputFile("output1.txt");
...
}

void function2()
{
std::ifstream inputFile("input2.txt");
std::ofstream outputFile("output2.txt");
...
}

Either way its a good idea when asking 'how do I ...' questions to post
the code you have already written. It's often easier to understand what
you want to do then. If you haven't already written some code, then it's
probably good for you to attempt to do so before asking the group.

john
Sep 13 '05 #3
What exactly do u mean by 'initalise' the files ? Please be more
specific

Sep 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
3798
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
2
5816
by: Mary | last post by:
Hello, I am having a problem with the cl compiler. I have written a C class (RegConnect.c) which uses Win32 API functions such as RegOpenKey, RegCloseKey etc. Initially when I was trying to...
5
6428
by: rnorthedge | last post by:
I am working on a code library which needs to read in the data from large binary files. The files hold int, double and string data. This is the code for reading in the strings: protected...
12
2032
by: bj7lewis | last post by:
I am working on a project I want to add a few files as resource to access(copy them to FS and use) at runtime. So far in VS.NET IDE, I Add Files to the project and set its Build Action to...
6
17139
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
52
4056
by: mavic | last post by:
hi to everybody,i need help for my project....how to make a program that accept any integer and convert it binary,octal and hexadecimal.pls help me...thanks
0
1368
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any...
15
2970
by: JoeC | last post by:
I am writing a program that I am trying to learn and save binary files. This is the page I found as a source: http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html I have...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.