Kill me for asking this (STL issues)

This is a discussion on Kill me for asking this (STL issues) within the C++ Programming forums, part of the General Programming Boards category; Got this small code which results in "windows has encountered a problem with this and has to close it down ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    34

    Angry Kill me for asking this (STL issues)

    Got this small code which results in "windows has encountered a problem with this and has to close it down etc etc " error
    It happens at user input

    Code:
    #include<iostream>
    #include<list>
    #include<string>
    
    using namespace std ;
    
    struct Movie
    {
    	string MovieName;
    	string MovieDirector;
    	string MovieActor;
    	string MovieActress;
    	string MovieGenre;
    	int MovieRating;
    
    };
    
    int main()
    {
    	string MName;
    	string name;
    	
    	list<Movie> Movie_List;
    	list<Movie>::iterator ListIterator;
    
    	cin>>name;
    
    	ListIterator = Movie_List.begin();
    	ListIterator->MovieName = name ;
    	ListIterator = Movie_List.begin();
    	cout<<ListIterator->MovieName;
    	return 0 ;
    
    
    }
    Last edited by roalme00; 01-10-2008 at 05:14 AM. Reason: nature of problem changed
    I am in love with c++...Hence i broke off with my girl

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Can you please post the actual error?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    Quote Originally Posted by matsp View Post
    Can you please post the actual error?

    --
    Mats
    error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>

    my newbie brain cant make anything of this error...

    googled the error for about an hour but to no avail...

    *tears in my eyes *
    I am in love with c++...Hence i broke off with my girl

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,632
    Perhaps you forgot to include a header, or perhaps something else. Try posting a small program that demonstrates the error.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    damn my noobish negligence....i had forgotten to include string header

    now it compiles fine ...it even links fine...but when i enter a movie name (which is read by cin>>name;

    the program crashes saying

    "windows has encountered a problem with this and must be closed etc etc"

    edited my original post which now contains the entire code that i am trying to run

    should i commit suicide ?
    Last edited by roalme00; 01-10-2008 at 05:12 AM.
    I am in love with c++...Hence i broke off with my girl

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You forgot to include <string>; you only have <iostream>. Which, on MS, unfortunately is enough for the string class, but not for its I/O routines.

    Furthermore: dereferencing the begin iterator of an empty list is undefined! Use push_back() to actually get the movies into the list:
    Code:
    Move A_Movie;
    std::cin >> A_Movie.MovieName;
    Movie_List.push_back(A_Movie);
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    Indeed...it works now...many thanks to all...( and dont rejoice...it wont be long before i come up with more annoying questions)

    thanks
    I am in love with c++...Hence i broke off with my girl

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to kill a dragon with various programming languages
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-01-2007, 12:13 PM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM

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