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

int main(){
  tuple<string, string, string> x;
  x = make_tuple("hi", "a", "b");
  cout << get<0>(x) << endl << endl;

}

I've been having difficulties with my program, so I wrote a simpler one and even this does not work. I do not understand why there is a problem after reviewing the documentation several times. It also compiles fine on XCode but for some reason breaks down on g++.

Here is the full error message:

test.cpp:6:3: error: use of undeclared identifier 'tuple'

tuple x;

^

test.cpp:6:9: error: unexpected type name 'string': expected expression

tuple x;

    ^

test.cpp:7:3: error: use of undeclared identifier 'x'

x = make_tuple("hi", "a", "b");

^

test.cpp:7:7: error: use of undeclared identifier 'make_tuple'

x = make_tuple("hi", "a", "b");

  ^

test.cpp:8:11: error: reference to overloaded function could not be resolved; did you mean to call it? cout << get<0>x << endl << endl;

The command I am using is g++ test.cpp

JobHunter69
  • 1,706
  • 5
  • 25
  • 49

2 Answers2

6

Try #include <string>.

Possibly (depending on your version og gcc) you also need -std=c++11 on the command line.

jbab
  • 469
  • 4
  • 9
1

The tuple is fine; what you're trying to make it a tuple of is not.

You did not #include <string>!

Thus the word "string" means nothing to your compiler, and it has no idea what you want it to do. It can't even tell that you meant it to be a type, so it can't tell that by the word "tuple" you meant "std::tuple". So on, and so forth…

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055