Le Forum de Drupal Study
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.

Trying to create a vector using a structure definition as the basis in VC++ 2013

Aller en bas

Trying to create a vector using a structure definition as the basis in VC++ 2013 Empty Trying to create a vector using a structure definition as the basis in VC++ 2013

Message par  Mer 30 Jan - 3:43

2013 2013 2013


[Vous devez être inscrit et connecté pour voir ce lien]



I'm using a header file to define the structure:



#ifndef EINSTEIN_H

#define EINSTEIN_H



#include

#include







struct SizeAll{

double year;

double R;

SizeAll() { year = 0; R = 0; }

};







int write_to_file(int count, struct SizeAll *data, char const



*fileName)

{

FILE* fp;

fp = fopen(fileName, "w");

if (fp == NULL) return -1;

while (count-- > 0) {

fprintf(fp, "%d,%d\n", data->year, data->R);

//check for errors writing to file

if (ferror(fp)) return -1;

}

fclose(fp);

return 0;

}

#endif





I've loaded the following in the "main.cpp" equivalent. (Not called "main.cpp", but serves the same purpose.)

#include "stdafx.h"

#include

#include

#include "Einstein.h"

#include

#include "Form1.h"



The code that actually seeks to generate the vector using the structure definition follows:





int counter,year,retval,count;

vector Universe;

Universe.resize(5);

vector *heretis;

char const NameFile[]="D:\\Friedout.csv";



heretis=&Universe;

Universe.R = double(366);

Universe.year = double(188);

for ( counter = 15000 ; counter > 99 ; counter-- )

{

Universe.year =double(counter);

Universe.R = double(counter*2);

if (counter==100||counter ==2500||counter==5000||counter==7500||counter==10000||counter==12500||counter==15000)

{

retval=write_to_file(1, heretis, NameFile);

if (retval ==-1)

{

break;

}

}

}





This creates quite a mess. It seems that somehow the "vector" declaration isn't working as the referenced web link seems to suggest that it should. I presume that, as usual, clearing one real error will eliminate the cascade of errors the first real error produces. Can anyone clear this up for me? Why won't VC++ accept the "vector" identifier? Thank you.



The error messages that follow the build attempt are:



Friedman.cpp

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(22): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) : see declaration of 'fopen'

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(80): warning C4067: unexpected tokens following preprocessor directive - expected a newline

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2065: 'vector' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2275: 'SizeAll' : illegal use of this type as an expression

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(9) : see declaration of 'SizeAll'

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(83): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(83): error C2228: left of '.resize' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2065: 'vector' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2275: 'SizeAll' : illegal use of this type as an expression

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(9) : see declaration of 'SizeAll'

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2065: 'heretis' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(87): error C2065: 'heretis' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(87): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(88): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(88): error C2228: left of '.R' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(89): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(89): error C2228: left of '.year' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(92): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(92): error C2228: left of '.year' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(93): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(93): error C2228: left of '.R' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(96): error C2065: 'heretis' : undeclared identifier

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========</div>


2013 2013 2013 security programming design programs game system software hardware scripting dynamic programming designs disney college program design star proxy list ecommerce Amelia Islands Amsterdam Antique Chairs Apartment for Rent Aquarium Asthma Astronomy Athletes Foot Baby Boomers Background Check Ballroom Dancing Bankruptcy Barbecues BBQs Bean Bags Bipolar Bird Houses Bird Watching Blinds Body Building Body Detox Bonsai Bowling Breast Augmentation Bronchitis Budgeting Bullying Business Mentoring Calcium Calibration Candle Making candles Careers Carpets cats Cheffing Childrens Parties Chinese Tea Christmas Decorations Comic Books Computer Training Copyright Credit Repair Criminal Records cuff links Dating Day Outings Designer Footwear Direct Mail Marketing Domain Names Drug Addiction ecommerce Educational Toys Elderly Care Electrician Essential Oils Estrogen European Travel Family Fishing Fitness Articles Fly Fishing Forums Fruit Trees Genealogy Gift Ideas Goal Setting Golf Green Decking And Patios hail loss Harley Davidson Hiking Hiking and Camping



[Vous devez être inscrit et connecté pour voir ce lien]



I'm using a header file to define the structure:



#ifndef EINSTEIN_H

#define EINSTEIN_H



#include

#include







struct SizeAll{

double year;

double R;

SizeAll() { year = 0; R = 0; }

};







int write_to_file(int count, struct SizeAll *data, char const



*fileName)

{

FILE* fp;

fp = fopen(fileName, "w");

if (fp == NULL) return -1;

while (count-- > 0) {

fprintf(fp, "%d,%d\n", data->year, data->R);

//check for errors writing to file

if (ferror(fp)) return -1;

}

fclose(fp);

return 0;

}

#endif





I've loaded the following in the "main.cpp" equivalent. (Not called "main.cpp", but serves the same purpose.)

#include "stdafx.h"

#include

#include

#include "Einstein.h"

#include

#include "Form1.h"



The code that actually seeks to generate the vector using the structure definition follows:





int counter,year,retval,count;

vector Universe;

Universe.resize(5);

vector *heretis;

char const NameFile[]="D:\\Friedout.csv";



heretis=&Universe;

Universe.R = double(366);

Universe.year = double(188);

for ( counter = 15000 ; counter > 99 ; counter-- )

{

Universe.year =double(counter);

Universe.R = double(counter*2);

if (counter==100||counter ==2500||counter==5000||counter==7500||counter==10000||counter==12500||counter==15000)

{

retval=write_to_file(1, heretis, NameFile);

if (retval ==-1)

{

break;

}

}

}





This creates quite a mess. It seems that somehow the "vector" declaration isn't working as the referenced web link seems to suggest that it should. I presume that, as usual, clearing one real error will eliminate the cascade of errors the first real error produces. Can anyone clear this up for me? Why won't VC++ accept the "vector" identifier? Thank you.



The error messages that follow the build attempt are:



Friedman.cpp

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(22): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) : see declaration of 'fopen'

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(80): warning C4067: unexpected tokens following preprocessor directive - expected a newline

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2065: 'vector' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2275: 'SizeAll' : illegal use of this type as an expression

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(9) : see declaration of 'SizeAll'

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(83): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(83): error C2228: left of '.resize' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2065: 'vector' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2275: 'SizeAll' : illegal use of this type as an expression

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(9) : see declaration of 'SizeAll'

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2065: 'heretis' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(87): error C2065: 'heretis' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(87): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(88): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(88): error C2228: left of '.R' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(89): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(89): error C2228: left of '.year' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(92): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(92): error C2228: left of '.year' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(93): error C2065: 'Universe' : undeclared identifier

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(93): error C2228: left of '.R' must have class/struct/union

type is ''unknown-type''

d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(96): error C2065: 'heretis' : undeclared identifier

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========</div>


Home Automation Home Business Home Schooling Homeopathy Honeymoon Hydroponic Garden Identity Theft Jazz Job Hunting Preparation Joint Venture Landscape Design Latin Dance Law School Lawn Care Lean Manufacturing license Local Recreation Locksmith Marriage Meditation Metal Detector Mexico Mortgages Motor Homes Moving Mutual Funds Natural Insecticides Natural Insectiside Nursing Assistant Obsessive Compulsive Disorder Online Dating Origami Outdoor Swing Outsourcing Paintball Penny stocks Pet Grooming Pet Insurance Pet Parrots Pets Photography Physiotherapy Potty Training Power Tools Private Investigation Prom Hairstyles Prototyping Public Domain Rawfood Diet Recycling Resume Safari Vacations Salad and Dressing Ideas Scholarship Scuba Diving Self Improvement Setting Goals Single Parenting Skiing Skiing Locations Skin Care small business Snowmobiles social networking Spectrum Analysers Spiders Sports Apparel Sports Nutrition Spring Makeup Stained Glass Stress Student Loan Bad Credit Summer Animal Care Summer Fashion Trends Summer Fitness Summer Heat Summer Jobs Summer Savings Summer Travel Summer Vacations Supercross Surround Sound Sweeteners Swimming Pool Ownership Taekwondo Tattoo Technology And Gadgets Termites Time Management Timeshare Toy Trains Trademarks Trading Triathlon Trophies Vacuum Cleaners Vegetarian Vitamins and Supplements Wedding Etiquette Wedding Themes Wheelchair Lifts Wild Flowers Windsor Pilates Working Dogs2013 2013 2013
avatar

points : 0

Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum