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

typedef struct blook
{
	char* name;
	int hour;
	char* day;
	char* month;
	char* year;
	char* alive;
	char* sick;
	char* pregnant;
	char* adult;
	char* elderly;
	char* child;
	char* water;
	char* meat;
	char* wood;
	char* seeds;
	char* vegtables;
}info;
info load(string name1)
{
	info black;
	black.name = "";
	black.hour = 0;
	black.day = 0;
	black.month = 0;
	black.year = 0;
	black.alive = 0;
	black.sick = 0;
	black.pregnant = 0;
	black.adult = 0;
	black.elderly = 0;
	black.child = 0;
	black.water = 0;
	black.meat = 0;
	black.wood = 0;
	black.seeds = 0;
	black.vegtables = 0;
	ifstream file(name1.c_str());
	//strcpy(black.name, name.c_str());
	getline(file, black.hour);
	file.getline(black.day, 5);
	file.getline(black.month, 5);
	file.getline(black.year, 5);
	file.getline(black.alive, 5);
	file.getline(black.sick, 5);
	file.getline(black.pregnant, 5);
	file.getline(black.adult, 5);
	file.getline(black.elderly, 5);
	file.getline(black.child, 5);
	file.getline(black.water, 5);
	file.getline(black.meat, 5);
	file.getline(black.wood, 5);
	file.getline(black.seeds, 5);
	file.getline(black.vegtables, 5);
	file.close();
	return black;

}

now when i build that code i get this

1>------ Build started: Project: tribal sim, Configuration: Debug Win32 ------
1>Compiling...
1>tribe sim.cpp
1>c:\users\brandon\documents\visual studio 2008\projects\tribal sim\tribal sim\save.h(45) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(527) : see declaration of 'std::getline'
1>c:\users\brandon\documents\visual studio 2008\projects\tribal sim\tribal sim\save.h(45) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(527) : see declaration of 'std::getline'
1>c:\users\brandon\documents\visual studio 2008\projects\tribal sim\tribal sim\save.h(45) : error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(475) : see declaration of 'std::getline'
1>c:\users\brandon\documents\visual studio 2008\projects\tribal sim\tribal sim\tribe sim.cpp(45) : error C2664: 'atoi' : cannot convert parameter 1 from 'int' to 'const char *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Users\Brandon\Documents\Visual Studio 2008\Projects\tribal sim\tribal sim\Debug\BuildLog.htm"
1>tribal sim - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

what am i doing wrong?

The first problem is that you use char* instead of string.

The second is that you're using getline wrong:

getline(file,black.day);

There are a couple of problems.
getline in the form that you have it on line 45 (with the filestream as a parameter instead of as the object) takes a std::string for the second parameter. Your second parameter is an int.

You can either read it in as a string and parse it with something like atoi (for example, many options here) or use file>>black.hour; to take it in directly.

Edited 6 Years Ago by jonsca: n/a

This article has been dead for over six months. Start a new discussion instead.