Sign in to follow this  
dolphins87

Visual C++ 2008 Complier Problems With Strings

Recommended Posts

when I go to complie simple code from a book im using I get these error messages. 1>.\main.cpp(4) : error C2065: 'string' : undeclared identifier 1>.\main.cpp(4) : error C2146: syntax error : missing ')' before identifier 'first' 1>.\main.cpp(4) : error C2182: 'printName' : illegal use of type 'void' 1>.\main.cpp(4) : error C2059: syntax error : ')' 1>.\main.cpp(7) : error C2064: term does not evaluate to a function taking 2 arguments 1>.\main.cpp(10) : error C2065: 'string' : undeclared identifier 1>.\main.cpp(10) : error C2146: syntax error : missing ')' before identifier 'first' 1>.\main.cpp(10) : error C2182: 'printName' : illegal use of type 'void' 1>.\main.cpp(10) : error C2374: 'printName' : redefinition; multiple initialization 1> .\main.cpp(4) : see declaration of 'printName' 1>.\main.cpp(10) : error C2059: syntax error : ')' 1>.\main.cpp(11) : error C2143: syntax error : missing ';' before '{' 1>.\main.cpp(11) : error C2447: '{' : missing function header (old-style formal list?) 1>Build log was saved at "file://c:\Users\dolphinsa87\Desktop\Book 1 Chp 4\4.9\Debug\BuildLog.htm" 1>4.9 - 12 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== but I have checked my folders and the string.h is there. I don't know if I jus have my compler setup correctly but I can seem to find the anwsers anywhere. Here is the code if u need that to.
#include<iostream>
#include<stdlib.h>
#include<string>
void printName(string first, string second);
int main()
{
	printName("Thomas","Jefferson");
	return 0;
}
void printName(string first, string second)
{
	string fullName = first + " " + second;
	std::cout << fullname << std::endl;
}

Share this post


Link to post
Share on other sites
There are three ways you can solve your problem :

- you can place a : using namespace std; right after the include region which is frowned upon because you do not need all the definitions in the std namespace

- you can place a : using std :: string; right after the include region

- you can put std :: in front of every string declaration

Also : instead of std::cout << fullname << std::endl;
std::cout << fullName << std::endl;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this