For example Im trying to make the user input his name, last name, and salary and then make it display " First Name is" followed by what they put in as their first name "Last Name is" followed by what he put as his last name... and now im getting all sorts of errors

Fairly new to this so any information would be greatly appreciated

Thanks for your time.

#include <iostream>

int main()
{
	string firstName;
	string lastName;
	int salary;

	std::cout << "Enter First Name, Last Name, Salary";
	std::cin >> firstName >> lastName >> salary;
	
	std::cout << "\nFirst Name is " << firstName;

	std::cout << "\nLast Name is " << lastName;

	std::cout << "\nSalary is " << salary;

	return 0;
}

Add this line to your declarations area:

using namespace std;

if you do that it works, and i think you should also get rid of all of the “std::” in your code。

this is what my program would look like if i were to write that program:

#include <iostream>

using namespace std;

int main()
{
	string firstName;
	string lastName;
	int salary;

        cout << "Enter First Name, Last Name, Salary";
	cin >> firstName >> lastName >> salary;
	
	cout << "\nFirst Name is " << firstName;

	cout << "\nLast Name is " << lastName;

	cout << "\nSalary is " << salary;

	return 0;
}

Qualify string identifier with std

#include <iostream>

int main()
{
	std::string firstName;
	std::string lastName;
	int salary;

	std::cout << "Enter First Name, Last Name, Salary";
	std::cin >> firstName >> lastName >> salary;

	std::cout << "\nFirst Name is " << firstName;
	std::cout << "\nLast Name is " << lastName;
	std::cout << "\nSalary is " << salary;
	return 0;
}

Two replies (one from a mod), and both are horrid. You both completely missed the fact that the <string> header wasn't included, which means any use of the std::string try (qualified or no) will fail miserably.

*sigh*

Here is the corrected[1] code. I added the <string> header and qualified the types because the OP was using explicit qualification for cout and cin:

#include <iostream>
#include <string>

int main()
{
  std::string firstName;
  std::string lastName;
  int salary;

  std::cout << "Enter First Name, Last Name, Salary";
  std::cin >> firstName >> lastName >> salary;

  std::cout << "\nFirst Name is " << firstName;
  std::cout << "\nLast Name is " << lastName;
  std::cout << "\nSalary is " << salary;

  return 0;
}

[1] There are still issues, but the immediate problem has been fixed.

Edited 7 Years Ago by Narue: n/a

Comments
Good suggestion!

Thanks Narue.
I really appreciate your help. I apologize for the inconvenience.

Edited 7 Years Ago by __avd: n/a

Two replies (one from a mod), and both are horrid. You both completely missed the fact that the <string> header wasn't included, which means any use of the std::string try (qualified or no) will fail miserably.

*sigh*

Here is the corrected[1] code. I added the <string> header and qualified the types because the OP was using explicit qualification for cout and cin:。。。。。。

。。。。。。[1] There are still issues, but the immediate problem has been fixed.

#include <iostream>

using namespace std;

int main()
{
	string firstName;
	string lastName;
	int salary;

        cout << "Enter First Name, Last Name, Salary";
	cin >> firstName >> lastName >> salary;
	
	cout << "\nFirst Name is " << firstName;

	cout << "\nLast Name is " << lastName;

	cout << "\nSalary is " << salary;

	return 0;
}

Hmm。。。I’m using dev c++ with the default gcc/g++ compiler, and this exact code works fine for me。 I thought it was the #include〈string〉, but for me that didn't matter as long as I was using the right namespace, do I have something configured incorrectly?

Two replies (one from a mod), and both are horrid. You both completely missed the fact that the <string> header wasn't included, which means any use of the std::string try (qualified or no) will fail miserably.

*sigh*

Here is the corrected[1] code. I added the <string> header and qualified the types because the OP was using explicit qualification for cout and cin:

[1] There are still issues, but the immediate problem has been fixed.

what do you mean by "there are still issues"?
still, thank you all for giving me a hand-really appreciate it.

>I’m using dev c++ with the default gcc/g++ compiler, 
>and this exact code works fine for me

There's nothing to stop a compiler from including standard headers in other standard headers. In your case, <iostream> includes <string> somewhere along the line. However, it's extremely poor practice to rely on this kind of behavior.

>what do you mean by "there are still issues"?
Cleaning up the output, checking user input for success/failure...that kind of thing. It's not a huge deal at this point in time, so I didn't mention those things.

Edited 7 Years Ago by Narue: n/a

This question has already been answered. Start a new discussion instead.