Error C2228


Hello. I have just started to learn some coding the past few days. I have written some stuff but now I am having a problem learning the printf(). Im not sure what is wrong in this code can someone please help?

The error : Error C2228: left of '.c_str' must have class/struct/union

The name section is working but not the Age part. Thank you for any help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;
int main()

{
	cout << "name?" << endl;
	string name;
	cin >> name;
	cout << "Age?" << endl;
	int Age;
	cin >> Age;
	printf("%s,", name.c_str());
	printf("%d,", Age.c_str());
}
Is this code C++ or C?
Just pass the integer directly to printf. Integers don't have a c_str() member function.

 
printf("%d,", Age);
Sorry I should of said c++

Thank you peter, that worked. Im learning from a book and it never explained it well. Thanks again :)
Topic archived. No new replies allowed.