Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-02-2005, 09:34 AM   #1 (permalink)
toast28
Registered User
 
Join Date: Sep 2004
Posts: 21
toast28 is on a distinguished road
quick question on fstream

Hey, I need to open a file in my newest program. I need it to simulate the log on of an operating system. It needs to read in a database of usernames and then output any attempts to log in, either allowed or denied.

My problem is that when I restart my program, it rewrites the entire output file. I need it to read the output, and stop right before the eof().

I tried using
while(!outfile.eof())
outfile >> junk;

but that brings me all the way to the end of file and won't write any more. Any ideas?
toast28 is offline   Reply With Quote
Old 02-02-2005, 12:13 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Especially look at how I opened the file.
"ios::app" means, "append".
Code:
#include <iostream>
#include <fstream>
#include <string>

std::ofstream outfile("namelog.txt", std::ios::app);

int main()
{
  std::string sName("Alex Bosman");
  
  //Otherwise the names will be concat. on the same line.
  outfile << std::endl;
  outfile<<sName;
 
  return 0;
}
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DB Design Question Part II sde Program Design and Methods 10 09-02-2008 11:37 AM
Quick question on <table>'s Redline HTML, XML, Javascript, AJAX 3 10-30-2004 08:12 PM
Quick way to select a random array element? Epsilon PHP 4 03-11-2004 04:49 PM
another question Ilya020 HTML, XML, Javascript, AJAX 5 08-20-2003 11:54 AM
Quick anti-aliasing question ntws01 Java 2 03-20-2003 06:00 PM


All times are GMT -8. The time now is 10:56 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting