Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ query

Name: Anonymous 2010-05-06 13:08

  
    int listsize, count;
    cout<<"Define size of list: ";
    cin>>listsize;
    cout<<endl;
    int list[listsize];


Are there any problems with this? It works fine but I just want to make sure I'm not committing a faux pas.

Name: Anonymous 2010-05-06 16:30


cin>>listsize;


Never ever EVER do that.1

Do this:

#include <sstream>
#include <string>

and

string line;
getline( cin, line );
stringstream( line ) >> list[count];


Now that's proper input!2

_________________________________________________________________
1 It's bad, it will break cin, it will break your skull, and those of your family and friends.
2 And it will hax your anus, ANUS THE HAXUS

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List