3 Replies - 856 Views - Last Post: 03 April 2013 - 02:48 PM Rate Topic: -----

#1 osu1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 17-June 12

Array of Structs gives Implicit capture errors

Posted 02 April 2013 - 11:07 PM

Hello guys, I am running a practice program to learn structs but my compiler gives me a ton of errors and after looking at the book not sure what I did wrong.

Is it because I did not initialize it? Do you always have to initialize an array of structs?

#include <iostream>
using namespace std;
#include <string>

struct Student
{
	string studentID;
	string firstName;
	string lastName;
	int credits;
	string major;
};


int main() 

{
	const int NUMSTUDENTS=2;
	Student stulist=[NUMSTUDENTS];
	
	cout << "Hello please enter id" << endl;
	cin >> stulist[0].studentID;
	cout << "Hello please enter first name" << endl;
	cin>> stulist[0].firstname;
	cout << "Hello please enter last name " << endl;
	cin>> stulist[0].lastname;
	cout << " Hello please enter the number of credits" << endl;
	cin>> stulist[0].credits;
	cout << "Hello please enter the major" << endl;
	cin>> stulist[0].major;

	cout << "Hello please enter id" << endl;
	cin >> stulist[1].studentID;
	cout << "Hello please enter first name" << endl;
	cin>> stulist[1].firstname;
	cout << "Hello please enter last name " << endl;
	cin>> stulist[1].lastname;
	cout << " Hello please enter the number of credits" << endl;
	cin>> stulist[1].credits;
	cout << "Hello please enter the major" << endl;
	cin>> stulist[1].major;


	cout << "Here are your results" << endl;
	cout << "Id 1 is" << stulist[0].sutdentID;
	cout << "Name 1 is " << stulist[0].firstname;
	cout << "Name last is" << stulist[0].lastname;
	cout << "Credit number is" << stulist[0].credits;
	cout << "Major is" << stulist[0].major;

	cout << "Here are your results" << endl;
	cout << "Id 1 is" << stulist[1].sutdentID;
	cout << "Name 1 is " << stulist[1].firstname;
	cout << "Name last is" << stulist[1].lastname;
	cout << "Credit number is" << stulist[1].credits;
	cout << "Major is" << stulist[1].major;

	return 0;
}

This post has been edited by osu1: 02 April 2013 - 11:14 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Array of Structs gives Implicit capture errors

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5777
  • View blog
  • Posts: 12,591
  • Joined: 16-October 07

Re: Array of Structs gives Implicit capture errors

Posted 03 April 2013 - 04:05 AM

Syntax errors?
Student stulist=[NUMSTUDENTS];


Was This Post Helpful? 0
  • +
  • -

#3 osu1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 17-June 12

Re: Array of Structs gives Implicit capture errors

Posted 03 April 2013 - 02:41 PM

View Postbaavgai, on 03 April 2013 - 04:05 AM, said:

Syntax errors?
Student stulist=[NUMSTUDENTS];



How is it a syntax error? I got it out a text bond saw similar other examples for it.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 3989
  • View blog
  • Posts: 12,307
  • Joined: 25-December 09

Re: Array of Structs gives Implicit capture errors

Posted 03 April 2013 - 02:48 PM

Try removing the '='.

If that doesn't fix you up, post the complete error messages exactly as they appear in your development environment.


Jim

This post has been edited by jimblumberg: 03 April 2013 - 02:49 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1