Hey everyone,
So I took a programming class 4 years ago in college and thought I'd never have to use it again. Well turns out writing a C++ program for my job would be very helpful.
I'm trying to import an array from a text file. I remember seeing in a different thread that I need to delete a couple build files but I can't remember where I saw it or what to delete.
is my code. It compiles with no errors but when I run it, I do not see the array and the only output I get is
The array is [1 2 3; 4 5 6; 7 8 9].
Any help would be appreciated.
Anthony
So I took a programming class 4 years ago in college and thought I'd never have to use it again. Well turns out writing a C++ program for my job would be very helpful.
I'm trying to import an array from a text file. I remember seeing in a different thread that I need to delete a couple build files but I can't remember where I saw it or what to delete.
Code:
#include<iostream>
using namespace std;
#define MAX 3 //maximum for array
#include<fstream>
int main(void) //start main function
{int i, j; //declare integers
double array[MAX][MAX]; //declare array
ifstream infile; //pointer with permission to read from a file
infile.open("/users/anthony/desktop/123.txt"); //choose infile
if(!infile) //check infile
{ cout<<"Could not find data file to open. Check file name or location."<<endl; //check
return 0;}
//read in array
{
for (i=0;i<3;i++)
for (j=3;j<MAX;j++)
{
cin>>array[i][j];
}}
for (i=0;i<3;i++){
for (j=3;j<MAX;j++)
{
cout<<array[i][j];
}}
return 0;}
is my code. It compiles with no errors but when I run it, I do not see the array and the only output I get is
Anthony-MacBook-Pro-2:~ Anthony$ /Users/Anthony/Desktop/Particle\ Analysis\ Final/build/Debug/Particle\ Analysis\ Final ; exit;
0logout
[Process completed]
The array is [1 2 3; 4 5 6; 7 8 9].
Any help would be appreciated.
Anthony