how come i cant compile these files in visual studio...

Discussion in 'OT Technology' started by D1G1T4L, Oct 12, 2005.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    i create an empty console c++ application
    with 2 source files
    List.c
    Code:
    #include <list>
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <string>
    #include <stdexcept>
    #include "List.h"
    using namespace std;
    
    List::List() : count(0)
    {
    } 
    
    bool List::empty() const
    {
       return count == 0;
    } 
    
    int List::size() const
    {
       return count;
    } 
    
    void List::insert(int index, ListItemType newItem)
            throw(ListIndexOutOfRangeException, ListException)
    {
       if (count >= MAX_LIST)
    
          throw ListException("ListException: List full on insert");
    
       if (index >= 1 && index <= count+1)
       {
          for (int pos = count; pos >= index; --pos) 
    		items[translate(pos+1)] = items[translate(pos)];
    
          items[translate(index)] = newItem;
          ++count; // increase the count of the list by one
       }
       else 
    
         throw ListIndexOutOfRangeException(
          "ListIndexOutOfRangeException: Bad index on insert");
    } 
    
    void List::remove(int index)
            throw(ListIndexOutOfRangeException)
    {
       if ((index < 1) || (index > size()))
    
          throw ListIndexOutOfRangeException(
          "ListIndexOutOfRangeException: remove index out of range");
    
       else
       {  
    
          for (int fromPosition = index+1;fromPosition <= count; ++fromPosition)
              items[translate(fromPosition-1)] = items[translate(fromPosition)];
          --count; // decrease the count of the list by one
       } 
    } 
    
    ListItemType& List::get(int index) 
            throw(ListIndexOutOfRangeException)
    {
       if ((index < 1) || (index > size()))
          throw ListIndexOutOfRangeException(
          "ListIndexOutOfRangeException: retrieve index out of range");
       else
          return items[translate(index)];
    } 
    
    
    int List::translate(int index) const
    {
       return index-1;
    } 
    
    
    
    
    fibonacci.c
    Code:
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <string>
    #include <stdexcept>
    #include <iomanip>
    #include "List.h"
    
    using namespace std;
    
    
    int main(int argc, char *argv[])
    {
    
    } // end main
    
    
    and 2 header files

    List.h
    Code:
    #ifndef _LIST_H_
    #define _LIST_H_
    
    #include "Exception.h"
    
    const int MAX_LIST = 1500;
    typedef char ListItemType;
    
    class List
    {
    public:
    
      List(); // default constructor
     
      // destructor is supplied by compiler
    
      //operations:
    
      bool empty() const; 
      // Same as isEmpty() in the textbook 
    
      int size() const; 
      // Same as getLength() in the textbook 
    
      void insert(int, ListItemType)
          	throw(ListIndexOutOfRangeException, ListException);
    
      void remove(int)
           	throw(ListIndexOutOfRangeException);
    
      ListItemType& get(int) 
           	throw(ListIndexOutOfRangeException);
      // Same as retrieve() in the textbook 
      // the item is returned using "return" statement
    
    
    private:
    
      ListItemType items[MAX_LIST]; // array of list items
      int count;                    // number of items in list
      int translate(int) const;	// translate index to pos
    }; 
    
    #endif
    
    Exception.h
    Code:
    #include <stdexcept>
    #include <string>
    using namespace std;
    
    class ListIndexOutOfRangeException: public out_of_range
    {
    public:
       ListIndexOutOfRangeException(const string & message = "")
                            : out_of_range(message)
       { }
    }; // end ListIndexOutOfRangeException
    
    
    class ListException: public runtime_error
    {
    public:
       ListException(const string & message = "")
              : runtime_error(message)
       { }
    }; // end ListException
    
    

    and the errors i keep getting is this

     
  2. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Looks like it's having some sort of problem with the libraries. Works just fine for me with g++.
     
  3. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    yea it works in g++ but it annoys the hell out of me cause it doesnt work in visual studio.net
     
  4. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    i don't think you're supposed to use stdio with VS .NET anymore. I think it wants you to use the managed IO shit. I remember running into this a few months ago. Think I ended up going back to the older VS
     
  5. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    my buddy with the same files said the project works if you rename the .c files into .cpp, i'll try that later
     
  6. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    typical MS resolution :rolleyes:
     
  7. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Out of curiosity... what app are you making that you would wanna use C++ in windows?
     
  8. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    rename your files to have .cpp extensions
     
  9. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    school's project :hs:


    anyways my solution is = Editplus + cygwin
     
  10. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    i decided i'lll only use visual studio for C#
     
  11. uneek

    uneek OT Supporter

    Joined:
    Dec 14, 2003
    Messages:
    12,002
    Likes Received:
    0
    just a wild guess, but are any of the files the school's files ? edited by the school?

    I remember back in HS I had problems with files that I got from school... and college was even worse trying to get some of the stuff to work right with VS.
     

Share This Page