Trouble using a .dat file

I have been given an assignment where I must build a function that will read data from a file sig.dat, which is just an ordinary text file with two columns of numbers. I missed the lecture where these files were introduced to the class, and while I have since developed an understanding of how to read information from such files, the problem I'm encountering is how to open them.

I've looked online in several tutorials, but they only seem to cover how write or read from external files, not where they're stored. I need to download sig.dat from a website, and I've tried saving it on the desktop and in the project folder in Visual Studio, but neither attempt worked. When I tried to compile a program that used it, the file couldn't be opened.

Any help would be much appreciated. Thanks
Put the file in the same directory as your program's executable. If you are on Linux, make sure it has the proper permissions. Then open it with something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <fstream>
#include <iostream>
using namespace std;

int main()
  {
  fstream f( "sig.dat" );

  if (!f) complain();  // make sure the file opened - if not complain in some way

  f >> foo;  // read from the file

  etc

Hope this helps.
Topic archived. No new replies allowed.