i need help finding a file that is needed for a program i am writing, the file is ALWAYS never found or an error within the file prevents the compiler to work, im newer to xcode and really need help. i have tried .dat .txt .rtf file types for the needed file, i have created it within the xcode program, along with trying to make them in the folder of the Cpp file and the debugger(basically every folder within my xcode library.
here is the code
//
// main.cpp
// STATISTICS
//
// Created by Home on 3/9/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <math.h>
#include <exception>
#include "info.dat"
//length of the array
usingnamespace std;
void readinsales(float sales[], int size);
float largest(float sales[]);
float smallest(float sales[]);
float average(float sales[]);
float total(float sales[]);
void organize(float *array);
int main(){
float account[10];
std::ifstream sales;
sales.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try {
sales.open ("info.dat");
}
catch (std::ifstream::failure e){
std::cout << "File not Found!" << '\n' <<"Press ENTER to exit program";
std::cin.ignore();
return 0;
}
for(int i = 0; i <= 10 ; i++){
sales >> account[i];
}
organize(account);
std::cout << account[1] << '\n' << account[2];
sales.close();
return 0;
}
void organize(float *array){
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(array[i]>array[j])
{
int temp=array[i]; //swaps the value
array[i]=array[j];
array[j]=temp;
}
}
}
}
currently this is using a .dat file which is finds and says "PARSE ISSUE" "EXPECTED UNQUALIFIED-id" which i have no real idea what this mean, can some1 who is experience with xcode please help me. like a walkthrough and explanation of how to reference files with xcode in c++ would be amazing.
include is not used to include some raw data file in your program. It is used to add C++ code that is in an other file inthe place of the include. That's why the compiler says that it doesn't understand what you told it to compile.
If you want to include your file's data directly in your executable, you can for example create an array of chars, where each byte would be one byte of the original file, and access it directly in memory afterwards. Or use the file manipulation classes.
I know that include is for actual code I'm just throwing things at it, I have tried locating files in every folder that is under desktop(where it is stored) I have also thrown #define and #import along with not doing eny of those 3.
If you want to put your file elsewhere, you need to specify the full path of the file.
could u give me an example of that please that's one thing I have not tried, and I'm not very familiar with the File setup for Mac