Solved

string in VC++

Posted on 2004-10-17
3
313 Views
Last Modified: 2010-04-01
Hi experts,

   Does anyone know why I failed to do the following declaration in VC++ ? thanks !!!
  (while I got no error without "string mystring;" ) please help ! thanks !!!

 #include "string.h"
  string mystring ;
-------------------------------
ompiling resources...
Compiling...
StdAfx.cpp
Compiling...
Bullet.cpp
GameObject.cpp
Monster.cpp
MyMap.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\MyMap\MyMap.cpp(48) : error C2146: syntax error : missing ';' before identifier 'mystring'
C:\Program Files\Microsoft Visual Studio\MyProjects\MyMap\MyMap.cpp(48) : error C2501: 'string' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\MyMap\MyMap.cpp(48) : fatal error C1004: unexpected end of file found
Generating Code...
Error executing cl.exe.

MyMap.exe - 3 error(s), 0 warning(s)
0
Comment
Question by:meow00
3 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 300 total points
ID: 12336010
string.h is the include file for ANSI-C string functions, not C++ string classes.

try #include <string>  instead.



0
 
LVL 1

Author Comment

by:meow00
ID: 12336017
Hi I got exactly the same errors by using "#include <string>" ... :-(
0
 
LVL 12

Expert Comment

by:OnegaZhang
ID: 12336148
#include <string>
std::string mystringvar;

or
#include <string>
using namespace std;
string mystringvar;
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now