What is worng with this code?
This code shows...
setw.obj : error LNK2005: _main already defined in filel.obj
Debug/filel.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

filel.exe - 2 error(s), 0 warning(s)

#include <iostream>
using std::cerr;
using std::cout;
using std::endl;
#include <fstream>
using std::ifstream;
#include <cstdlib> // for exit function
// This program reads values from the file 'example.dat'
// and echoes them to the display until a negative value
// is read.
int main()
   ifstream indata; // indata is like cin
   int num; // variable for input value
  indata.open("c:\\Downloads\\example.txt"); // opens the file
   if(!indata) { // file couldn't be opened
      cerr << "Error: file could not be opened" << endl;
  indata >> num;
   while ( !indata.eof() ) { // keep reading until end-of-file
      cout << "The next number is " << num << endl;
      indata >> num; // sets EOF flag if no value found
   cout << "End-of-file reached.." << endl;
   return 0;
6 Years
Discussion Span
Last Post by Ancient Dragon

You most likely have a project that contains two or more *.cpp files, and two of the files have main() defined in them. Delete the one you don't want.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.