prototype function error when i try to pass a string.

I am really confused because when I try to do a simple string pass it gives me a "string:undecalred identifier" and "syntax error: missing ')' before identifier 'x'."getJars:identifier not found" It gives me no issues when do another datatype.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <fstream>
#include <string>
#include <iostream>


void getJars(string x);
using namespace std;

int main()
{

	getJars("6");
	

	
}

void getJars(string x) {
	cout << "hi " << x;
}
The function prototype is above using namespace std; so you need to write void getJars(std::string x);.

Since your function prototype is before the using namespace line you need to fully scope the std::string.

Topic archived. No new replies allowed.