If I have a 40,000 word dictionary in the file:
LatinDictionary.txt
How would I output that file to the screen?

Member Avatar for iamthwee

Read it in, then cout it. But the console window will only display the last part. You can't scroll up to the very beginning.

commented: Master of the obvious. ;) -4

Here's what I did:

[LIST=1]
[*]#include <iostream>
[*]#include <fstream>

[*]  
[*]  using namespace std;
[*]  int main()
[*]  
[*]  {
[*]    ifstream in_stream;
[*]     in_stream.open ("LatinDictionary.txt");
[*]     cout << in_stream << endl;
[*]    
[*]  
[*]                                                                                                       
[*]    getchar();
[*]    return 0;
[*]}
[/LIST]

It outputs to the screen 0x22fed4.

For simplicity sake:

#include <fstream>
#include <iostream>
#include <string>

int main()
{
  std::ifstream in ( "myfile" );

  if ( in ) {
    std::string word;

    while ( in>> word )
      std::cout<< word <<'\n';
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.