Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

string in VC++

Posted on 2004-10-17
3
Medium Priority
?
329 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 1200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

972 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