Jul 26, 2008

Adding Myfileexists Function To My Basic Code?

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

free web hosting

Adding Myfileexists Function To My Basic Code?

kvarnerexpress
Here is a short and basic piece of my first ever application written in Visual C++ 6.0 . I have also commented the code well to show you EXACTLY what my code is meant to do with each function. What exactly I am asking for, is for someone to please replace anywhere that you see "EXISTS" with the proper function "myFileExists" to actually check to see if the file exists. Also I am asking for anyone that may see an error in this code, to please point it out to me and how I can fix it.

If anyone can help me with getting this very basic code to work, it would be GREATLY appreciated. Here it is:


Code:
#include <iostream.h>
#include <string.h>

main ()
{
string File; // define "File" as a string

if (File == FILENAME) // define "File" as a "Filename"
{
if (File EXISTS) // check if "File" exists
{
cout << "MESSAGE" << endl; // if so displays appropriate message
}
}
else // if "File" doesn't exist
{

if (File == FILENAME) // define "File" as NEW "Filename"
{
if (File EXISTS) // check if NEW "File" exists
{
cout << "MESSAGE" << endl; // if so displays appropriate message
}
}
}
else // if "File" doesn't exist
{

if (File == FILENAME) // define "File" as NEW "Filename"
{
if (File EXISTS) // check if NEW "File" exists
{
cout << "MESSAGE" << endl; // if so displays appropriate message
}
}
}
else // if "File" doesn't exist
{

if (File == FILENAME) // define "File" as NEW "Filename"
{
if (File EXISTS) // check if NEW "File" exists
{
cout << "MESSAGE" << endl; // if so displays appropriate message
}
}
}
else // if "File" doesn't exist
{

if (File == FILENAME) // define "File" as NEW "Filename"
{
if (File EXISTS) // check if NEW "File" exists
{
cout << "MESSAGE" << endl; // if so displays appropriate message
}
}
}
else // if "File" doesn't exist
{

if (File == FILENAME) // define "File" as NEW "Filename"
{
if (File EXISTS) // check if NEW "File" exists
{
cout << "MESSAGE" << endl; // if so displays appropriate message
}
}
}

return (0);
}


PS = I know I could use a loop for this, but this just complicates everything for me with creating new arrays and such. I would like to start SIMPLE as I do not need to check for more than 6 different files.

Thanks ALOT in advance!!


Peace.

 

 

 


Reply

OpaQue
This is to warn you about your post. You are supposed to put the CODEs in [ CODE ] tag. I have reduced 5 Hosting credits from your account. If I had considered your complete post as spam, you could have lost more.

Consider this as a friendly warning. smile.gif

Reply

dexter
What is all this for anyway?

Anyway, a few tips before I start. You're using C++, so actually -use- C++.

#include <iostream> as opposed to #include <iostream.h>

The first is the C++ header, the second is the C header... use the first...

#include <string> - C++ style strings
#include <cstring> - Functions for C style strings (aka char*)

Again, use the C++ style.

A lot of other headers are slightly different in C++ than C...

e.g. <math.h> is <cmath>
<stdlib.h> is <cstdlib>


Okay, on to the testing.

I'm not going to give you the function, you'll need to work out that yourself, but I'll explain briefly about filestreams. These classes are included in the <fstream> header. You'll most likely need to add after your header declarations:

CODE

using std::ifstream;
using std::ofstream;


if you don't have

CODE

using namespace std;



There are three types of filestreams: ifstream, ofstream and fstream.

ifstream is for extracting data from files only.
ofstream is for outputting data to files only.
fstream is a two way interface for files.

Now, whenever you want to use a filestream, you need to declare it first.

CODE

// fin and fout are used because filestreams work nearly identically
// to the standard I/O cin and cout (except for a few extra functions).
ifstream fin;            
ofstream fout;


Then, you need to open the file. The member function is declared as:

CODE

void open(const char *s,
       ios_base::openmode mode);


Now for the different streams, the default mode differs. Ifstreams default mode is ios::in, ofstreams default mode is ios::out, and fstreams default mode is ios::in | ios::out.

These basically describe how the file is going to be used... input, ouptut, or both. There are other options, but you can look into them as you need to.

Based off our original declarations, we'll open a file:

CODE

fin.open("test.txt", ios::in);
fout.open("test2.txt, ios::out);


Ok, the question is, are they open. The fstream class provides another function for filestream called, is_open(). This function returns true if the file was opened.

CODE

if(fin.is_open())
 cout << "test.txt opened\n";
else
 cout << "test.txt couldn't be opened\n";

if(fin.is_open())
 cout << "test2.txt opened\n";
else
 cout << "test2.txt couldn't be opened\n";


Another way of testing if a file could be opened is to test if the filestream has failed...

CODE

if(fin.fail())

or

if(fout.fail())


Now, when you open a file for outputting, unless something seriously goes wrong, or there's already a write protected file, the file will always be opened. This is because if the file doesn't exist, a new file is created.

For input, on the other hand, it will fail if the file doesn't exist.

And last of all, whenever you're done with a file make sure to close it.

CODE

fin.close();
fout.close();


Hope that makes enough sense for you to use. If there are any details missing... use your MSDN, google, or ask here. biggrin.gif

Good luck.

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : adding, myfileexists, function, basic, code

  1. Making A Simple Signature With Adobe Photoshop
    A tutorial to basic signature designing: By Accure (3)
  2. PHP Function To Add Previous and Next Page Feature
    useful php function (0)
    CODE <?php function navigationbar($start_number = 0, $items_per_page = 50,
    $count) {    // Creates a navigation bar    $current_page =
    $_SERVER["PHP_SELF"];     if (($start_number < 0) ||
    (! is_numeric($start_number))) {         $start_number = 0;     }
        $navbar = "";     $prev_navbar = "";     $next_navbar =
    "";     if ($count > $items_per_page) {         $nav_count = 0;
            $pag....
  3. Adding Flash Music Player To Home/any Page
    How-to (put any song you want!!!) (4)
    Want to put music on all pages (near the top)? Want any song you want? Well heres how! Place the
    following IN PLACE of the tag (paste in while thats highlighted. The text in red you HAVE to
    replace with the song url. The text in green is OPTIONAL (whether you want it to autostart or not.
    Right now it doesnt, if you want it to replace no with yes.) Of course place this in Admin
    Cp>>>Skinning and Styles>>>Board Wrappers>>>Header and Body QUOTE REPLACE THIS
    WITH YOUR SONG URL &autoStart= no " /> src="http://www.podbean.com/podcast-au....
  4. Add Flashing Inbox To Invisionfree Forum
    Html code for invsiionfree!! (0)
    Do you find it annoying when you are on your invisionfree forum, and you get a new message, and it
    ends up taking you 5 minutes to notice? This code makes the inbox link flash bold red saying how
    many messages you have. In version 1 the word inbox stays the same, and doesnt change at all (for
    Example this is flashing: Inbox (2) In version 2 (the second code) the word inbox changes to
    messages (constantly, so that if you have none, it says messages (0) instead of inbox (0). It still
    flashes Red Put the following In the Header and Body Section (Admin Cp>>>Skinning ....
  5. Why Doesn't This Code Work On Computinghost?
    (2)
    Here is the script: Rcon Connection Client IP: Port: Password Cmd:
    $ip = $_POST ; if (!$ip) die(); $port = $_POST ; if
    (!$port) die(); $pass = $_POST ; if (!$pass) die(); $passlen =
    strlen($pass); $cmd = $_POST ; if (!$cmd) die(); $cmdlen =
    strlen($cmd); $packet = 'SAMP'; $packet .= chr(strtok($ip,
    '.')).chr(strtok('.')).chr(strtok('.')).chr(strtok('.'));
    $packet .= ch....
  6. Basic Of Website Creation
    Get basic knowledge on website creation here (6)
    By basic, i mean reaaaal "BASIC". I know that its probably redundant info for so many of us, but I
    still would like you to add your bit into this post , so that newbies benefit from it.....
  7. Create Table - Mysql Code - Help
    (1)
    I need your feedback about setting the database issues. Please, review them and correct some entries
    in the code if they got some mistakes. This is the code itself: SQL CREATE TABLE
    `news` ( `id` int(250) NOT NULL auto_increment, `title` varchar(255)
    NOT NULL default '', `text` text NOT NULL, `author` varchar(255) NOT
    NULL default '', `valid` varchar(255) NOT NULL default '',
    `date` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE = ....
  8. Php Source Code Unveiled In Browser?
    is that possible? (7)
    I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
    PHP is not correctly configured on the web server the source code of a php file we try to access
    through a browser will be shown instead of the result of the code itself. This will normally not
    happen when PHP is working properly, but I was just wondering if it could still be possible to see
    that code if a user wanted to or if something on the server failed. This would for example expose
    sensitive information like mysql passwords and so on... Is anything like that possib....
  9. Mozilla: Firefox Plugin Shipped With Malicious Code
    (3)
    This piece of news only affect Vietnamese users as the Vietnam language package was infected with
    malware trojan called e Xorer, and so if you downloaded this language pack in the last few weeks run
    a scan and the trojan should be picked up. Although this trojan is only a couple of months old and
    so I don't think everyone has something for it, but check at your vendors website and see if
    they have a solution for it. As for the cause of this infected plugin, they assume the authors
    computer was infected at the time when they upload this plugin to the mozilla website....
  10. Ti Basic: Pick A Number
    (1)
    Description Learn how to create a neat-o Game in TI Basic. Its basic premise is that someone
    picks a number, then they pass the calculator to their friend, and they try to guess the number.
    Once the successfully guess the number a message appears and says that they have won. I have also
    included a line that keeps users from choosing numbers greater than one-hundred. Please Enjoy.
    Try I Out Alright.... just input what you see below and I'll explain it a little below.
    CODE :ClrHome :Lbl 2 :Prompt A :A->X :If X>100 :Goto 2 &#....
  11. Aob Blood Grouping
    Few Basic Idea for all (1)
    AOB blood grouping is the most common blood grouping in present world. In this grouping blood
    grouped depending on presence and absence of antigen A and antigen B in blood. Blood groups in AOB
    system are A, B, AB and O. I am trying to explain this blood grouping system as easy as possible so
    that the member of this site who has no science background can also understand the system. If any
    blood contain antigen A but no antigen B, the blood group will be A blood group. If any blood
    contains antigen B but no antigen A, the blood group will be B blood group. If any blood co....
  12. Ti-basic --- Slot Machine
    (9)
    Description Ok, so this is my first TI-BASIC tutorial. In this tutorial you will learn how to
    create a very simple slot machine, so you can entertain yourself in math class /tongue.gif"
    style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> You will need at least a TI
    83 Calculator. Try it out Ok, first create a new program called 'SLOT MACHINE'. Hit the
    enter key. Now input the following code. CODE :ClrHome :Lbl 1
    :Output(1,1,"--Slot Machine--") :Output(2,1,randInt(0,9,1))
    :Output....
  13. Php Code?
    Mathematical Applications (12)
    Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
    like that a user just type in the fields known values, then click the button, and it's going to
    be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
    that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
    just can write the known value which is peremeter itself and it will find the side of a square; and
    vice versa. If you can write many things how to do such formulas, such as comp....
  14. Adding Drop Down Menus
    (4)
    I have looked around many IPB support sites, but I didn't find a suitable drop-down menu add-on
    that I liked or worked correctly. I have noticed the drop down menus on this forum on other forums,
    and I was wondering if this was custom to this site or there was a tutorial somewhere which shows
    how to make one similar to this? Or if anything, I basic IPB drop down menu tutorial/add on.
    Thanks.....
  15. How Do I Code A Design?
    (6)
    Okey, so I saw another topic here regarding how to make a design. I know how to do that, so that is
    no problem. But I have always had some problems on how to code a design. I am tired of that I always
    need to use some sort of program, drag&drop webhost (like piczo) or use a free design I found
    online. I have noticed that people need to "cut" the design in different parts, but I have never
    understood what way the do it. So I do not understand anything about this, and really need some
    help. I will be happy for all help I get. /smile.gif" style="vertical-align:middle"....
  16. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE <?php //Save this as something like htmltest.php function
    CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
    input $html_safe=str_replace("<?php"," ",$html_unsafe);
    //Starts security measures $html_safe=str_replace("?>","
    ",$html_sa....
  17. Help! Php Or Just Html?
    i want to start buliding my website. which is better, php or basic htm (13)
    i try to start this topic in webhost category but it seems like i cant. i dont have the permission
    so i just post my topic here. im sorry mod.. i want to build a website which contains: - Links to
    videos - Informations - photos - flash i don't know if i should use php or just HTML. guys,
    what are your opinions..??....
  18. Adding Your Website To Google
    How to register with google (20)
    Hi everyone. Hopefully here im going to tell you how to register yourself with the Google search
    engine and get yourself in their results. Ill start the tutorial assuming you already have Meta
    tags or other search engine optimisation techniques in place. This tutorial is solely about
    registering with google. At one time i thought simply using meta tags etcetera would get you listed
    in Google, i then found out that didnt work, so i wondered why, and the fruits of my labour are what
    will go into this tutorial. the first step is to get a google account, this will get y....
  19. Each And Every Nokia Code For Your Mobile
    (6)
    Nokia 3210/5110/6110 And All Most Works In Most Of The Nokia Phones. QUOTE To view IMEI number
    *#06# To view Software Version enter *#0000# To view Status of Sim Clock Stop. Enter *#746025625#
    Latest Version is under Phone Info Type is NSE-3NX *#92702689# offers you Serial Number and also
    IMEI number. There are various options to scroll here. The code is easier to remember as *#war0anty#
    (warranty) The next screen is the date of manufacture in the format Made: 1197 The next screen is
    the purchase date in the format Purchasing Date: 1197 (this can be edited) The nex....
  20. Wap Source Code Viewer
    Mobile/wap source code viewer page (4)
    This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
    work on web im sure ;-) CODE <? header("Content-Type:
    text/vnd.wap.wml"); echo '<?xml version="1.0"
    encoding="utf-8"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <head><meta
    http-equiv="Cache-Control" content="no-cache"
    forua="true"/></head> <card title="s60.nerds.....
  21. Simple C File Handling In Action
    Small code snipet which covers most of basic file handling and navigat (3)
    Yesterday I suddenly got a lot of work. The same work we try to push off, yes you are right all
    formalities to get the code review incorporated and update all source code files with code review
    headers. Imagine if you need to open 300 files one by one and append code review headers at the
    end. Since most files are reviewed in groups of 20 to 30 files. We require one header to be placed
    in say 20 to 30 files. To simplify I went back to my class assignment days and wrote this small c
    utility to open all files passed on command line and open attach code review headers an....
  22. Adding Rows & Columns In Html Table Using Javascript
    (1)
    I'm trying to create a website with a form that collects some user information to store in MySQL
    database. However, I've a problem when I want to dynamically add new rows and columns in the
    HTML table so that the user can add more information in the dynamically added textboxes. Here's
    what I have: CODE                  <table border="0" width="90%"
    align="center" id="itemsTable">                   <tr>
                       <td width="20%">                     Quantity                   
    <....
  23. Myspace Music Player
    Anyone have the code? (9)
    Hey, I was looking around on MySpace to see if they had a particular song with a player that you see
    on many different MySpaces, but they did not have one for the song I wanted. I was wondering if
    anyone had the proper code for a music player. I do have the song I want and have the capability to
    upload it, but I just need the code for it. If you can help at all I'd really appreciate it.
    Example on the top right of this MySpace (but I just want a one song player):
    http://www.myspace.com/ofarevolution ....
  24. Visual Basic 6.0 Help Needed
    Adding lines to a textbox without delete (13)
    I need help with Visual Basic 6.0 and adding lines to a textbox without deleting any previous
    lines.. I've gotten as far as finding a way to add the lines, but it deletes the prevous entree.
    Help is appreciated!....
  25. Making Winrar Archives
    and adding password to winrar archives (12)
    **** This tutorial will show you how to put files into .rar Archive and pass worded (if wanted)
    **** What You Will Need Before continuing you will need a couple of thing, first of all you
    need WINRAR , which is a very powerful archive manager. It can reduce size for you email
    attachments, decompress RAR, ZIP and other types of files downloaded from the internet. You can get
    winrar at http://www.rarlabs.com The other thing is that make sure your using Windows XP because
    this is what I used to make this tutorial. I think it works with any other windows not....
  26. Html Tag For A Code Box
    Where You Put HTML Code For Your Users (4)
    Well I have seen it all over the web. Lots of sites have code boxes so you can promote them or they
    show you a code you can use for javascript and stuff like that. I would like to know the HTML code
    for those boxes. Thanks in advance for your help.....
  27. Redirect Code Help
    (8)
    Can someone give me the code which redirects you automatically in the whole page instead of only in
    the frame? I'm using this code, but it just redirects inside a frame... CODE <meta
    HTTP-EQUIV="REFRESH" content="0; url=http://www.something.com"> But now
    .tk has added a ad to the pages so I don't want to use it anymore, so I want that people
    entering the site is being redirected to the "real" domain name now.......
  28. [tutorial] Visual Basic 6 Minimize To Tray
    Minimize to Tray (4)
    This example will "minimize" your program to the system tray when you click on a button, and restore
    it when you click the system tray icon. For this example you'll need: 1 Form - Form1 1 button -
    Command1 Add a Module to your project, and ad this code: CODE ' Create an Icon in System
    Tray Needs Public Type NOTIFYICONDATA cbSize As Long hwnd As Long uId As Long uFlags As Long
    uCallBackMessage As Long hIcon As Long szTip As String * 64 End Type Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1 Public Const NIM_DELETE = &H2 Public Const WM_MOUSEMOVE ....
  29. Need Help With My Python Programs
    just extremely basic stuff (11)
    ok, i am learning python, and i realy dont know much. my guide im using said to make a program
    where it asks your name, and if the name is yours your make it so there is a compliment, if it is
    another name you make it that its an insult, and anything else makes it say Nice name. here is what
    i wrote name = raw_input("What is your name?") if name == John: print "Your name is freaking
    sweet, you must be a god or something." elif name == Bob: print "You have a freakin' weird
    name, dude." else: print "Nice name,",name i donot understand what i am doing w....
  30. How do you test your php code
    (75)
    We know that php is a server side scripting language. So we will need a server with the php parser
    to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
    instal php and the server (apache) on your computer (localhost)....

    1. Looking for adding, myfileexists, function, basic, code

Searching Video's for adding, myfileexists, function, basic, code
Similar
Making A
Simple
Signature
With Adobe
Photoshop -
A tutorial
to basic
signature
designing:
By Accure
PHP Function
To Add
Previous and
Next Page
Feature -
useful php
function
Adding Flash
Music Player
To Home/any
Page -
How-to (put
any song you
want!
3;!)
Add Flashing
Inbox To
Invisionfree
Forum - Html
code for
invsiionfree
!!
Why
Doesn't
This Code
Work On
Computinghos
t?
Basic Of
Website
Creation -
Get basic
knowledge on
website
creation
here
Create Table
- Mysql Code
- Help
Php Source
Code
Unveiled In
Browser? -
is that
possible?
Mozilla:
Firefox
Plugin
Shipped With
Malicious
Code
Ti Basic:
Pick A
Number
Aob Blood
Grouping -
Few Basic
Idea for all
Ti-basic ---
Slot Machine
Php Code? -
Mathematical
Applications
Adding Drop
Down Menus
How Do I
Code A
Design?
Html Code
Tester.
Online
Script
Help!
Php Or Just
Html? - i
want to
start
buliding my
website.
which is
better, php
or basic htm
Adding Your
Website To
Google - How
to register
with google
Each And
Every Nokia
Code For
Your Mobile
Wap Source
Code Viewer
- Mobile/wap
source code
viewer page
Simple C
File
Handling In
Action -
Small code
snipet which
covers most
of basic
file
handling and
navigat
Adding Rows
&
Columns In
Html Table
Using
Javascript
Myspace
Music Player
- Anyone
have the
code?
Visual Basic
6.0 Help
Needed -
Adding lines
to a textbox
without
delete
Making
Winrar
Archives -
and adding
password to
winrar
archives
Html Tag For
A Code Box -
Where You
Put HTML
Code For
Your Users
Redirect
Code Help
[tutorial]
Visual Basic
6 Minimize
To Tray -
Minimize to
Tray
Need Help
With My
Python
Programs -
just
extremely
basic stuff
How do you
test your
php code
advertisement



Adding Myfileexists Function To My Basic Code?



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE