Error opening file

This is a discussion on Error opening file within the C++ Programming forums, part of the General Programming Boards category; I am getting these 2 errors when I try and open and write to a file Could someone please help, ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    56

    Question Error opening file

    I am getting these 2 errors when I try and open and write to a file
    Could someone please help, I don't understand what it is that I am doing wrong. Also when I did get it to open I couldn't write to the file. Here is my code

    Thank You

    Project4b.obj : error LNK2005: _main already defined in Project4a.obj

    fatal error LNK1169: one or more multiply defined symbols found

    [CODE]
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <ctime>
    #include <cstdlib>
    #include <fstream>
    #include <algorithm>
    int getNumbers(int &);


    using namespace std;
    int main()

    {

    //declare Variables

    string clerkid = "";
    string name = "";
    string address = "";
    string city = "";
    string state = "";
    string hyphfill = "";

    int zip = 0;
    int ssn = 0;
    int visa = 0;
    int pin = 0;

    //opens file CCApp.txt

    ifstream inFile;
    inFile.open("WACKOFILE.dat", ios::in);
    if(inFile.is_open())

    {

    getline(inFile,clerkid,'#');



    while(!inFile.eof())

    {

    inFile>>ssn;
    inFile.ignore(1);
    getline(inFile,name,'#');
    getline(inFile,address,'#');
    getline(inFile,city,'#');
    getline(inFile,state,'#');

    inFile>>zip;
    inFile.ignore(1);
    inFile>>pin;
    inFile.ignore(1);
    inFile>>visa;
    inFile.ignore(2);


    cout<<left<<setw(25)<<setfill(' ')<<"NAME"<<" "<<setw(25)<<"ADDRESS"<<" "<<left<<setw(16)<<"CITY"<<" "<<setw(2)<<
    left<<"ST"<<" "<<setw(5)<<left<<"ZIP";


    cout<<left<<setw(25)<<setfill('-')<<hyphfill<<" "<<setw(25)<<setfill('-')<<hyphfill<<" "<<left<<setw(16)<<setfill('-')<<hyphfill<<" "<<setw(2)<<left<<setfill('-')<<hyphfill<<" "<<
    setw(5)<<left<<setfill('-')<<hyphfill;

    cout<<left<<setw(25)<<setfill(' ')<<name<<" "<<setw(25)<<address<<" "<<left<<setw(16)<<city<<" "<<setw(2)<<left<<state<<" "<<setw(5)<<right<<
    setfill('0')<<zip<<endl;

    cout<<setw(7)<<left<<"CLERKID"<<" "<<setw(9)<<left<<setfill(' ')<<"SSN"<<" "<<setw(4)<<left<<setfill(' ')<<"PIN"<<" "<<setw(5)<<left<<setfill(' ')<<"VISA"<<" "<<endl;

    cout<<setw(7)<<left<<setfill('-')<<hyphfill<<" "<<setw(9)<<left<<setfill('-')<<hyphfill<<" "<<setw(4)<<left<<setfill('-')<<hyphfill<<" "<<setw(5)<<left<<setfill('-')<<hyphfill<<" "<<endl;

    cout << setw(7) << left << setfill(' ') << clerkid
    <<" "<<setw(9)<<right<<setfill('0')<<ssn<<" "<<setw(4)<<left<<setfill(' ')<<pin<<" "<<setw(5)<<left<<setfill(' ')<<visa<<" "<<endl;


    cout<<endl;
    cout<<endl;

    getline(inFile,clerkid,'#');



    }
    }
    else

    {cout<<"File not opened"<<endl;}
    inFile.close();

    cout << endl;
    return 0;
    [Code]

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    You need to remove Project4a.cpp from your Visual Studio project (or makefile or linker arguments or whatever). It is trying to link Project4a and Project4b, both of which have main functions.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    56

    Post

    I got that problem solve. The problem now is that when it opens the file it will not let me write or reade from it, all it says is press any key to continue and when I press a key it closes the window.

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    The problem now is that when it opens the file it will not let me write or reade from it, all it says is press any key to continue and when I press a key it closes the window.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21