Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
2-D Arrays in Visual C++ 2010
No permission to create posts
October 2, 2014
4:24 am
Avatar
bobten
Member
Members
Forum Posts: 4
Member Since:
May 13, 2014
sp_UserOfflineSmall Offline

Hello, I am having a trouble with creating an 101x101 array of integers, which is very important for a project I am working on.

What I thought at first was to declare the array in the header file and then give values to its contents by an external txt file in the constructor function. However, the program doesn't recognise the txt file with the integers. Is there a specific folder, where I should copy my txt file so that Visual Studio can find it? If you can help me find my errors, or try another way to initialise my array, I would be very grateful.

My code for the constructor is this:

#include "Ttn.h"
#include
#include
#include
#include
using namespace std;

CTtn::CTtn()
{
//...
//...
// Finish initializations here
fstream fin("ook.txt");
int n=101;
//if (!fin.fail())
//{
for (x111 = 0; (x111 < n) ; x111++)
{
for (y = 0; (y < n) ; y++){
fin >> Y1[x111][y];
}
}
fin.close();
//}

}

and my header file is this:

#pragma once

// base class
#include "plugin.h"
// abstract base class for RackAFX filters
class CTtn : public CPlugIn
{
public:

// Add your code here: ----------------------------------------------------------- //

int x111;
int y;
int n;
int Y1[101][101];

October 2, 2014
7:55 pm
Avatar
W Pirkle
Admin
Forum Posts: 143
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

Try using a complete path for the file like "C:\\SomeFolder\\ook.txt"

Notice the use of \\ to represent a single slash (see string delimiters...)

- Will

October 2, 2014
8:31 pm
Avatar
bobten
Member
Members
Forum Posts: 4
Member Since:
May 13, 2014
sp_UserOfflineSmall Offline

Will said

Try using a complete path for the file like "C:\\SomeFolder\\ook.txt"

Notice the use of \\ to represent a single slash (see string delimiters...)

- Will

Thank you very much for your answer! This worked great for my program. I had previously tried the full path but with single slashes and it caused compilation errors.

Forum Timezone: America/New_York

Most Users Ever Online: 36

Currently Online:
3 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Skyler: 47

Peter: 41

Derek: 41

clau_ste: 39

Frodson: 38

Gwen: 32

EZB: 24

lppier: 23

Msaldaña: 18

Jorge: 17

Member Stats:

Guest Posters: 1

Members: 476

Moderators: 1

Admins: 4

Forum Stats:

Groups: 11

Forums: 30

Topics: 482

Posts: 1876

Newest Members:

sam, annaharris, Marie Weaver, kev, Steven, Mr Anderson, mguy, omelc

Moderators: W Pirkle: 143

Administrators: Tom: 65, JD Young: 80, Will Pirkle: 0, W Pirkle: 143