Click here to Skip to main content
15,898,947 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: error with inserting the record in database Pin
Hamid_RT30-Oct-06 18:27
Hamid_RT30-Oct-06 18:27 
QuestionTabs, toolbars, views, and MFC... Pin
dontknowitall30-Oct-06 11:13
dontknowitall30-Oct-06 11:13 
AnswerRe: Tabs, toolbars, views, and MFC... Pin
Mark Salsbery30-Oct-06 12:08
Mark Salsbery30-Oct-06 12:08 
GeneralRe: Tabs, toolbars, views, and MFC... Pin
dontknowitall30-Oct-06 16:33
dontknowitall30-Oct-06 16:33 
Questioninputing string & int from file to array. Pin
Ramper30-Oct-06 9:43
Ramper30-Oct-06 9:43 
QuestionRe: inputing string & int from file to array. Pin
David Crow30-Oct-06 9:47
David Crow30-Oct-06 9:47 
AnswerRe: inputing string & int from file to array. Pin
Ramper30-Oct-06 9:52
Ramper30-Oct-06 9:52 
GeneralRe: inputing string & int from file to array. Pin
Zac Howland30-Oct-06 10:45
Zac Howland30-Oct-06 10:45 
This is a starting place (it isn't complete, but it should get you started):

#include <string>
#include <vector>
#include <algorithm>
#include <interator>
#include <iostream>
#include <fstream>

class Student
{
public:
	Student() : _Name("") {}
	~Student() {}

	void setName(const std::string& name) { _Name = name; }
	std::string& getName() const { return _Name; }

	void setGrades(const std::vector<int>& grades) { _Grades.assign(grades.begin(), grades.end()); }
	std::vector<int>& getGrades() const { return _Grades; }
private:
	std::string _Name;
	std::vector<int> _Grades;
};

std::ostream& operator<<(std::ostream& os, const Student& s)
{
	os << s.getName() << " ";	// NOTE:  older versions of STL will require a character buffer instead
	const std::vector<int> grades = s.getGrades();
	std::copy(grades.begin(), grades.end(), std::ostream_iterator<int>(os, " "));
	os << std::endl;
	return os;
}

std::istream& operator>>(std::istream& is, Student& s)
{
	string name = "";	// NOTE:  older versions of STL will require a character buffer instead
	is >> name;
	std::vector<int> grades;
	std::copy(std::istream_iterator<int>(is), std::istream_iterator<int>(), std::back_inserter(grades));
	s.setName(name);
	s.setGrades(grades);
	return is;
}

int main()
{
	std::ifstream fin;
	std::vector<Student> students;
	fin.open("MyData.txt");
	std::copy(std::istream_iterator<Student>(fin), std::istream_iterator<Student>(), std::back_inserter(students));
	fin.close();
	// do whatever you want with students vector
}


If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

QuestionRe: inputing string & int from file to array. Pin
David Crow30-May-07 9:24
David Crow30-May-07 9:24 
AnswerRe: inputing string & int from file to array. Pin
Zac Howland31-May-07 5:43
Zac Howland31-May-07 5:43 
GeneralRe: inputing string & int from file to array. Pin
David Crow31-May-07 6:00
David Crow31-May-07 6:00 
GeneralRe: inputing string &amp; int from file to array. Pin
Zac Howland31-May-07 7:44
Zac Howland31-May-07 7:44 
QuestionRe: inputing string &amp; int from file to array. Pin
David Crow31-May-07 8:42
David Crow31-May-07 8:42 
AnswerRe: inputing string &amp; int from file to array. Pin
Zac Howland31-May-07 9:07
Zac Howland31-May-07 9:07 
GeneralRe: inputing string &amp; int from file to array. Pin
David Crow1-Jun-07 4:13
David Crow1-Jun-07 4:13 
QuestionCPrintDialog issue Pin
Andy H30-Oct-06 8:59
Andy H30-Oct-06 8:59 
QuestionVS 2003 .NET System Path Pin
BlitzPackage30-Oct-06 8:20
BlitzPackage30-Oct-06 8:20 
AnswerRe: VS 2003 .NET System Path Pin
Mark Salsbery30-Oct-06 9:01
Mark Salsbery30-Oct-06 9:01 
GeneralRe: VS 2003 .NET System Path Pin
BlitzPackage30-Oct-06 9:11
BlitzPackage30-Oct-06 9:11 
GeneralRe: VS 2003 .NET System Path Pin
Mark Salsbery30-Oct-06 9:37
Mark Salsbery30-Oct-06 9:37 
GeneralRe: VS 2003 .NET System Path Pin
BlitzPackage30-Oct-06 10:16
BlitzPackage30-Oct-06 10:16 
QuestionON_MESSAGE event Pin
edvintas30-Oct-06 6:33
edvintas30-Oct-06 6:33 
AnswerRe: ON_MESSAGE event Pin
Mark Salsbery30-Oct-06 6:37
Mark Salsbery30-Oct-06 6:37 
GeneralRe: ON_MESSAGE event Pin
edvintas30-Oct-06 6:41
edvintas30-Oct-06 6:41 
GeneralRe: ON_MESSAGE event Pin
Mark Salsbery30-Oct-06 6:47
Mark Salsbery30-Oct-06 6:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.