1

Lately I have been trying to store strings in variables. I did quite a few searches online, and most of the answers that I have found recommend the use of std::string. So I've written a test program that looks like this:

#include <iostream>
#include <string>
using namespace std;

int main(){
    string s;
    getline(cin,s);
    cout << s;
}

The program compiles fine, however, when I run the program I revieve this error:`Error Message

I am a huge beginner to programming and confused on what is going on. Can anyone please give me some insight on what is happening here? Thanks!

Also, I am using the GCC compiler.

EDIT: I have successfully solved the issue. All I did was reinstall GCC using a tutorial on the web. I do not know what was wrong, but it is fixed now.

McGrizz
  • 131
  • 2
  • 11
  • 1
    How are you compiling your code? – Kerrek SB Feb 25 '17 at 02:34
  • 1
    Use g++ instead of gcc. The second links the standard library automatically. – Retired Ninja Feb 25 '17 at 02:35
  • 1
    The missing symbol (after I fixed the typos) demangles to `std::__cxx11::basic_string, std::allocator >::basic_string()` which is better known as the default constructor for `std::string`. This is likely to be an installation problem. – zwol Feb 25 '17 at 02:35
  • 3
    You should show your command to compile the program. If you have not done so, then use `g++` instead of `gcc`; or use `gcc -x c++` to force c++ compilation. Also see [Converting std::__cxx11::string to std::string](http://stackoverflow.com/q/33394934/608639) on Stack Overflow and [GCC5 and the C++11 ABI](https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/) on the Red Hat blog. – jww Feb 25 '17 at 02:41
  • My compile code is "g++ -std=c++14 test.cpp -o test.exe" what do you think I should change to make this compile? Forgive me if you already answered this, but I am still very beginner so I'm not familiar with all this yet. – McGrizz Feb 25 '17 at 03:19
  • @Zachary try compiling your code using `clang++ `. – Ankit Panda Jul 09 '17 at 11:35

1 Answers1

2

When you use GCC to compile C++, you need to use the g++ driver program, not gcc. The latter will compile the translation units, but it will not link the executable correctly.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084