K
kazack
#include <iostream>
#include <fstream>
#include <string>
#include <io.h>
#include <cstring>
using namespace std;
enum Triangles{Scalene,Isosceles,Equalateral,Invalid,Hold};
Triangles Entered = Hold;
void NotValid(int, int, int);
void Equal(int,int,int);
void Isos(int,int,int);
void triangle(int,int,int,int);
void main()
{
ifstream inData;
int sidea;
int sideb;
int sidec;
char* filename;
// I have 2 options here char* filename = "c:\filename";
// or const char* filename ="c:\filename";
//either one will work when checking for file existance.
// but can not use it with a cin statement below.
cout << "Please Enter The Data File: ";
cin >> filename;
//the above line does not work I have tried numerous
//things and can not figure out how to get it to work.
//I do not want the filename hardcoded into the
//program!!
//The bit of code below works only if you use the
//char* filename. I have tried creating another variable
// and using strcpy and that does not work it keeps
//coming up with can not convert blah blah blah.
if((_access(filename,0))!=-1)
{
cout << filename << " Exists\n";
}
else
{
cout << filename << " Does Not Exist\n";
}
inData.open(filename);
I am new to c++ and it is more difficult than VB. If someone can help me
out with a solution that does what I want I would be very greatful.
My object is to:
1. Ask the user for the filename.
2. check for existance
3.If the file does not exist let the user create it or let
them use another data file.
I was thinking as an alternative checking for file existance using a system
call for a wildcard dat file and read them into an array and let the user
select the file or create a new one. But I thought the option above I am
trying to use would be more efficient and easier.
Thank You,
Shawn Mulligan
(e-mail address removed)
#include <fstream>
#include <string>
#include <io.h>
#include <cstring>
using namespace std;
enum Triangles{Scalene,Isosceles,Equalateral,Invalid,Hold};
Triangles Entered = Hold;
void NotValid(int, int, int);
void Equal(int,int,int);
void Isos(int,int,int);
void triangle(int,int,int,int);
void main()
{
ifstream inData;
int sidea;
int sideb;
int sidec;
char* filename;
// I have 2 options here char* filename = "c:\filename";
// or const char* filename ="c:\filename";
//either one will work when checking for file existance.
// but can not use it with a cin statement below.
cout << "Please Enter The Data File: ";
cin >> filename;
//the above line does not work I have tried numerous
//things and can not figure out how to get it to work.
//I do not want the filename hardcoded into the
//program!!
//The bit of code below works only if you use the
//char* filename. I have tried creating another variable
// and using strcpy and that does not work it keeps
//coming up with can not convert blah blah blah.
if((_access(filename,0))!=-1)
{
cout << filename << " Exists\n";
}
else
{
cout << filename << " Does Not Exist\n";
}
inData.open(filename);
I am new to c++ and it is more difficult than VB. If someone can help me
out with a solution that does what I want I would be very greatful.
My object is to:
1. Ask the user for the filename.
2. check for existance
3.If the file does not exist let the user create it or let
them use another data file.
I was thinking as an alternative checking for file existance using a system
call for a wildcard dat file and read them into an array and let the user
select the file or create a new one. But I thought the option above I am
trying to use would be more efficient and easier.
Thank You,
Shawn Mulligan
(e-mail address removed)