Hello,
I'm pretty new to C++ and I've been trying to this program to open a file and check if it exists for the last two hours. It seems like it should be so simple but it keeps eluding me. Here is the code in main that starts to run.
#include <stdio.h>
#include <QApplication>
#include <QFile>
#include <QtXml>
#include <QString>
#include <QtDebug>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
#include "showfile.h"
void makeSubDirectories (string v1x_dir_str, string v2x_dir_str);
RMS_ShowFile_v1 gShowFile_v1;
RMS_ShowFile_v2 gShowFile_v2;
int
main(int argc, char* argv[])
{
QCoreApplication a(argc, argv);
int i,j,k,l;
string path;
char first_line[50];
string fileType = ".shx";
if (argc < 2)
{
cout << "Enter showfile path: " << endl;
cin >> path;
}
else path = (argv[1]);
strcpy(first_line, path.c_str());
ifstream fp;
fp.open(first_line, ifstream::in);
if (!fp)
{
cout << "Invalid path to v2x showfile" << endl;
return 0;
}
When I go to test it in Xcode's runlog I get:
"[Session started at 2008-11-03 17:26:04 -0800.]
Enter showfile path:
showloadtest.shx //I typed this in
Invalid path to v2x showfile
showtest has exited with status 0."
It keeps saying my file does not exist but I definitely have the "showloadtest.shx" file in the same directory folder as my program. Is there something simple that I'm missing here? I've tried ifstream as well as fopen but to no avail.
Thanks in advance,
foggy_coder