CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2014
    Posts
    8

    (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unresolved

    I am working on a assignment for school and I am having some issues i havnetbeen able to figure out
    Name:  shot2.jpg
Views: 2015
Size:  94.8 KB Name:  shot1.PNG
Views: 1754
Size:  72.6 KB
    my first issue is that i keep getting these external errors and then my cout stopped working, i understand im supposed to overload them or something but I dont really understand how

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso

    Firstly, please don't post screen shots unless asked. We can't easily copy and paste the code into our own systems from them. Just do a normal copy and paste of code and then use code tags around the code (Go advanced, select the code and click '#').

    st1 is an instance of the class Student. The class function getID() doesn't actually get the id but displays the value to the cout stream and has a return type of void. This is about what the compiler is complaining. Either call st1.getID() directly to display the value - or better have getID() return the value which is what would be expected from the name of the function. ie
    Code:
    int Student::getID()
    {
         return ID;
    }
    The same comment also applies to the getName() class function.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Feb 2014
    Posts
    8

    Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso

    Thank you, for the quick responce and i managed to fix the cout issue but any ideas on fixing the external errors?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso

    Quote Originally Posted by tato1993 View Post
    Thank you, for the quick responce and i managed to fix the cout issue but any ideas on fixing the external errors?
    What type of project did you create?

  5. #5
    Join Date
    Feb 2014
    Posts
    8

    Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso

    Also here is the code
    this is the Student.h
    Code:
    #include<string.h>
    #include<string>
    #include<iostream>
    using namespace std;
    
    
    class Student
    {private:
    string fname;
    string lname;
    int ID;
    
    
    public:
    	Student();
    	Student(string first,string last, int ID_num);
    	static int numberOfStudents;
    	void getName();
    	int getID();
    
    };
    Here is my Student.cpp
    Code:
    #include <iostream>
    #include "Student.h"
    #include <string> 
    using namespace std; 
    
     Student::Student()
    {numberOfStudents+=1;
    }
    
    Student::Student(string first, string last, int ID_num)
    {fname=first;
    lname=last;
    ID=ID_num;
    numberOfStudents+=1;}
    
    int Student::numberOfStudents=0;
    
    void Student::getName()
    {cout<<fname<<lname;}
    
    int Student::getID()
    {return ID;}
     
    void main() 
    { 
     Student st1("Hakan", "Haberdar", 1234), st2("Charu", "Hans", 2345), st3("Tarikul", "Islam", 5442), st4; 
     cout << "We created " << Student::numberOfStudents << " student objects." << endl; 
     st1.getID();
    	 cout<< " ";
    	 st1.getName() ;
    	 cout<< endl; 
     st2.getID() ;
    	cout<< " " ;
    	st2.getName();
    	cout<<endl;
     st3.getID();
    	 cout<< " " ;
    	 st3.getName();
    	 cout<< endl; 
     st4.getID();
    	 cout<< " ";
    	 st4.getName(); 
    	 cout<< endl; 
    system("pause"); 
    }

  6. #6
    Join Date
    Feb 2014
    Posts
    8

    Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso

    Win 32 console Application

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso

    It looks like the linker can't find your main() function. You have main returning a type void but it should return a type int.

    Your code compiles and links OK for me using MSVS - so it's probably how a linker property has been set.

    Also <string.h> should be <cstring> in c++.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    Join Date
    Feb 2014
    Posts
    8

    Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso

    Idk if i should start a new thread but i ran into a new problem i tried creating a new class derived from this student class in its own .h, but whenever I use
    Code:
    #include "Student.h"
    it tells me it cant open the source code.
    Also im assuming my problem with the LNK is jus something on my version i got Microsoft Visual C++ 2010

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured