473,397 Members | 2,116 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,397 software developers and data experts.

open new file each loop iteration

Hola, C++ folk!

I want to have a do...while loop that works with a different file each
iteration, prompting the user for the file name to open and write.

The problem I am having is that the second time around the loop, my code
skips the file name prompting bit, using the file name from iteration number
1. I have seen this kind of problem before, but I can't remember how to
deal with it correctly. Code snippet below

Comments and suggestions appreciated...

Thanks!
Danny

/*--- start code --- */
do
{
/* prompt for output file, using the file name in brackets if
* no file name is give (i.e., the user hits return). This will overwrite
* the contents of the file if this file is not empty!!
*/
cin.clear();
output_file_name.erase();

cout << "Output file? [bldg_report] ";

getline(cin, output_file_name);
if(output_file_name.empty())
{output_file_name="bldg_report.csv";}
else
{output_file_name+=".csv";}

dataOut_report.open(output_file_name.c_str());
if(!dataOut_report)
{cout << "ERROR: couldn't open output file..."; return 1;}
else
{cout << output_file_name <<" opened OK, ready to start..." << endl;}

cout << "Enter name for this building: ";
getline(cin, building_name);
cout << "Enter short description: ";
getline(cin, building_description);

dataOut_report << building_name << endl;
dataOut_report << building_description << endl;

dataOut_report.close();
}while(user_is_not_finished() );

Jul 22 '05 #1
0 1320

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

Similar topics

2
by: Aggelos I. Orfanakos | last post by:
Hello. Under Gentoo Linux, I issue: $ python timeit.py python: can't open file 'timeit.py' $ ls -al /usr/lib/python2.3/timeit.py -rw-r--r-- 1 root root 9833 Oct 19 02:17...
3
by: Murasama | last post by:
Hi there, Im trying a simple file IO operation in Visual Studio .NET 2003 and it can't seem to open the file. If I run the exe in the debug directory it works fine but if I click the start...
6
by: Charles Morrall | last post by:
I have no experience with DB2 as such, but I've been tasked with configuring backup of a server running DB2 v8 on Windows Server 2003. I do have some experience with backups in general though. The...
2
by: nissiml | last post by:
hi, i'm trying to open a asp.net web page that list files from a Windows application like winword and select a file from it . what do i have to do to make it happen, is it simple ? Thanks in...
2
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for...
5
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end....
6
by: gonzlobo | last post by:
I've been using Python for a few days. It's such the perfect language for parsing data! I really like it so far, but I'm having a hard time reading a file, reading the first few hex characters &...
2
by: tanayashinde | last post by:
Hello Everybody. I want to write a prog in C to add customer details in cust.dat file. in which mode should i open the file?if i open in w+ it will overwrite every next time i open file. & if i...
2
by: irislarin | last post by:
I was wondering if i could ask for some advise. I wrote a script for my workplace that imports CSV data from a template sheet (with data) to a DB table. I wrote it with a series of loops so that I...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.