Solved

string in VC++

Posted on 2004-10-17
3
321 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

792 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