Author: Daniel Clausen
Date: 15:46:10 11/06/03
Go up one level in this thread
On November 06, 2003 at 18:01:35, macaroni wrote:
[snip]
>this however crashes in a big way, telling me that ifstream is undeclared, cout
>is undeclared and it still dislikes std::string BookLines[50000]. Seems like the
>#include files are a bit dodgy? if I add the h again, it works except for the
>std::string BookLines[5000]; on which it still fails to compile.
>any ideas?
Below the slightly changed program, which works for me. But first a few remarks:
(1)
The things 'ifstream', 'cout', 'cin' and thelike are all in the namespace 'std'.
So you either write 'std::ifstream', 'std::cout', 'std::cin' etc or you write
'using namespace std;' at the start and afterwards can use 'ifstream', 'cout'
and 'cin' directly (ie, w/o the need to specify the namespace again and again by
'std::') It's your choice. :)
(2)
I have no clue why your compiler doesn't like 'std::string BookLines[5000];' It
would help if you'd post the exact compiler output.
And here's the slightly changed program: (it even compiles under gcc 3.2.3 :)
#include <iostream>
#include <fstream>
#include <string>
int main()
{
int BookSize=0,x;
std::string BookLines[50000];
std::ifstream in("SEEBook");
if(!in)
{
std::cout << "Book not found!\n";
return 1;
}
while(getline(in, BookLines[BookSize]))
{
BookSize++;
}
std::cin >> x;
return 0;
}
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.