"Kevin Goodsell" <us*********************@neverbox.com> wrote in message
news:uU*****************@newsread2.news.pas.earthl ink.net...
Allan Bruce wrote:
I want to load config from a file. I know how to load in numbers using
an ifstream, but I cant get it to load a string. Can somebody tell me how
to load a string from file? Here is my code:
int mNumServers;
short *mPorts;
std::string *mServers;
std::string *mPaths;
std::ifstream infile(HST_SERVERS_FILE);
infile >> mNumServers;
AllocServersMem();
for (int i=0; i<mNumServers; i++)
{
std::string temp;
// XXX how do I load a string easily?
//infile >> mServers[i];
//infile >> mPaths[i];
infile >> mPorts[i];
}
infile.close();
I get an error saying that:
error C2679: binary '>>' : no operator found which takes a right-hand
operand of type 'std::string' (or there is no acceptable conversion)
Give us a minimal complete program that demonstrates the problem. As it
is, I don't believe you've provided sufficient information to diagnose
the problem.
-Kevin
Here is my minumum program and the file I would wish to load:
Thanks
Allan
// LoadServers.cpp
#include <fstream>
#define HST_SERVERS_FILE "servers.dat"
int main()
{
int mNumServers;
short mPorts;
std::string mServers;
std::string mPaths;
std::ifstream infile(HST_SERVERS_FILE);
infile >> mNumServers;
std::string temp;
// XXX how do I load a string easily?
infile >> mServers;
infile >> mPaths;
infile >> mPorts;
infile.close();
return 0;
}
// file to load - servers.dat
1
www.erg.abdn.ac.uk /servlet/WinGalagaHST 80