473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

C++ Files Generation

Hi Friends

I am writing a program in c++ where in i will extract a word (AB2345) from a input file and then i have to create a filename by this word , i.e AB2345.txt . Like this there are around 100
words with different numbers (eg, AB123,AB521......), i.e i have to create 100 files .

How should i implement this using fstream . Please Guide Me.


Thanks in Advance
Praveen
Mar 7 '07 #1
5 1771
horace1
1,510 Expert 1GB
Hi Friends

I am writing a program in c++ where in i will extract a word (AB2345) from a input file and then i have to create a filename by this word , i.e AB2345.txt . Like this there are around 100
words with different numbers (eg, AB123,AB521......), i.e i have to create 100 files .

How should i implement this using fstream . Please Guide Me.


Thanks in Advance
Praveen
what is the exact problem? how to do file IO in C++? see
http://www.cplusplus.com/doc/tutorial/files.html

how to manipulate strings to form file names? see
http://www.cplusplus.com/doc/tutorial/ntcs.html
Mar 7 '07 #2
what is the exact problem? how to do file IO in C++? see
http://www.cplusplus.com/doc/tutorial/files.html

how to manipulate strings to form file names? see
http://www.cplusplus.com/doc/tutorial/ntcs.html

I have a file in which there are a list of keywords like
AB123
AB124
AB125
AB126
AB127
AB128
AB129
AB130
AB131
AB132
AB133

Then i have to extract each keyword for example AB123 and create a file with name AB123.txt (and insert some other information which i will do).

So i needed help in creating file names .In C++ i am creating first filename as follows

string substring="AB123";
string Path="/root/praveen/";
string ext=".txt";
string filename=Path+substring+ext;
ofstream Myfile;
Myfile.open(filename.c_str());

So this type i create first file AB123.txt



Next how to create Second file AB124.txt . Should i use a for loop and take new file handlers each time in the loop for creation of a file.

Finally as solution i have to get the following files to be created:

AB123.txt
AB124.txt
AB125.txt
AB126.txt
AB127.txt
AB128.txt
AB129.txt
AB130.txt
AB131.txt
AB132.txt
AB133.txt



Please Help me



Thanks in Advance
Praveen
Mar 7 '07 #3
Ganon11
3,652 Expert 2GB
You will have to use ifstream to get the keyword - using getline(ifstreamVar, strVar) will accomplish this. Then you can add the filename root as before, and finally open an ofstream object (create a file) using the .c_str() of the final product.
Mar 7 '07 #4
Hi Friends

Thank you for ur suggestions. The problem got solved


praveen
Mar 8 '07 #5
Ganon11
3,652 Expert 2GB
Glad to hear it!
Mar 8 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
2
by: Skip Montanaro | last post by:
I updated the patch that supports PEP 304, "Controlling Generation of Bytecode Files" to apply cleanly against current CVS. I've tested it on Mac OS X (straight Unix build only). I'd appreciate...
6
by: Alan Krueger | last post by:
Is there a way to automatically include C# files (.cs) generated by a third-party tool into a Visual C# .NET build? It's possible the set of files generated by this tool might change. Adding...
7
by: venkatbo | last post by:
Hi all, We've managed to cross-compile (from i686 targeting ppc) python (2.4.2) binaries and extension modules. However we cannot figure out how to cross-compile the .py (of distribution)...
2
by: Gerard Kramer | last post by:
Hello, There is a slight problem with operator overloading in a program I attempt to start practising C++. It is a basic (not very original) game of life simulator. It uses two classes:...
0
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com...
0
by: C.W.Holeman II | last post by:
For info on the context of my question see the end of this posting. I have used resource files and xnlLanguage to control the language displayed in a Motif application. Simply dropping an...
0
by: arugulla | last post by:
hello all, I have done C# web service for extracting xml file nodes and generate the files for the correcsponding nodes in that parsed xml. When second time i want to overwrite those files I dont...
5
by: Raman | last post by:
Hi All, We have an old code base which (unfortunatelty) has some C files that include other C files:e.g File.c ===== #include<stdio.h> .. void someFunc(){
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.