clang doesn't like cin.ignore

Greetings! I've started first semester Computer Science, which isn't specifically a class in C++, but uses C++ to explore the concepts. Right now we are working with strings. My current problem is that our textbook code [which compiles just fine in MS VisualStudio], won't compile with g++. The code is:

1
2
3
4
	cout << "What is the name of item 1: ";
	cin.ignore;
	getline(cin, item1);


[doctorjlowe@David-Lowes-MacBook-Pro:Documents]$ g++ cashier.cpp -o cashier
cashier.cpp:30:2: error: reference to non-static member function must be called
        cin.ignore;
        ^~~~~~~~~~
1 error generated.
[doctorjlowe@David-Lowes-MacBook-Pro:Documents]$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix


So it looks like i need a more portable way to dispose of the newline. I did try changing cin.ignore; to cin.ignore(); based on what i read in some web searches, but that generated even more errors.
cin.ignore(); is correct. What errors does it give you?
With the parentheses in place, i get:

[doctorjlowe@David-Lowes-MacBook-Pro:Documents]$ gcc cashier.cpp -o cashier
Undefined symbols for architecture x86_64:
  "std::istream::ignore()", referenced from:
      _main in cashier-QsoE3T.o
  "std::istream::operator>>(float&)", referenced from:
      _main in cashier-QsoE3T.o
  "std::istream::operator>>(short&)", referenced from:
      _main in cashier-QsoE3T.o
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
      _main in cashier-QsoE3T.o
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
      _main in cashier-QsoE3T.o
  "std::ios_base::Init::Init()", referenced from:
      ___cxx_global_var_init in cashier-QsoE3T.o
  "std::ios_base::Init::~Init()", referenced from:
      ___cxx_global_var_init in cashier-QsoE3T.o
  "std::cin", referenced from:
      _main in cashier-QsoE3T.o
  "std::cout", referenced from:
      _main in cashier-QsoE3T.o
  "std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)", referenced from:
      _main in cashier-QsoE3T.o
  "std::terminate()", referenced from:
      ___clang_call_terminate in cashier-QsoE3T.o
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
      _main in cashier-QsoE3T.o
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<<<char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      _main in cashier-QsoE3T.o
  "___cxa_begin_catch", referenced from:
      ___clang_call_terminate in cashier-QsoE3T.o
  "___gxx_personality_v0", referenced from:
      _main in cashier-QsoE3T.o
      Dwarf Exception Unwind Info (__eh_frame) in cashier-QsoE3T.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gcc cashier.cpp -o cashier

Use g++ instead of gcc.
D'oh! How did i not notice that? And why doesn't gcc give a reminder when compiling a .cpp file in c mode??
Reminder? gcc is able to compile C++ code but the linking step fails because gcc doesn't link the C++ standard library by default.
Sure, but my point is: it would be more user-friendly if it gave some sort of a warning when given an instruction likely to fail. Anyways, thanks for your help.
Topic archived. No new replies allowed.