Solved

string in VC++

Posted on 2004-10-17
3
324 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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++.

749 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