Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error with std::string in header file using VS C++ 6.0 SP6

10 views
Skip to first unread message

Francis

unread,
Dec 2, 2004, 7:12:19 AM12/2/04
to
Can anybody help me with this code ? I contains errors I don't understand.
I use Visual Studio C++ 6.0, Service Pack 6.

CODE (header file)
====
#ifndef framing_h
#define framing_h

#include <vector>
#include <string>

std::string::size_type width (const std::vector<string>& v);
std::vector<string> frame (const vector<string>& v);
std::vector<string> vcat (const vector<string>& top, const vector<string>& bottom);
std::vector<string> hcat (const vector<string>& left, const vector<string>& right);

#endif


ERROR REPORT
============
error C2065: 'string' : undeclared identifier
error C2143: syntax error : missing ',' before '<'
error C2059: syntax error : '<'

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Thomas Mang

unread,
Dec 3, 2004, 6:29:48 AM12/3/04
to

"Francis" <francis...@hotmail.com> schrieb im Newsbeitrag
news:71714e61.04120...@posting.google.com...

> Can anybody help me with this code ? I contains errors I don't understand.
> I use Visual Studio C++ 6.0, Service Pack 6.
>
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>
> std::string::size_type width (const std::vector<string>& v);
> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>&
bottom);
> std::vector<string> hcat (const vector<string>& left, const
vector<string>& right);
>
> #endif


Well, you have to write 'std::string', and not only 'string' as you did in
the std::vector template argument list.


Thomas

Sharad Kala

unread,
Dec 3, 2004, 6:42:55 AM12/3/04
to

"Francis" <francis...@hotmail.com> wrote in message > Can anybody help

me with this code ? I contains errors I don't understand.
> I use Visual Studio C++ 6.0, Service Pack 6.
>
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>

> std::string::size_type width (const std::vector<string>& v);

std::string::size_type width (const std::vector<std::string>& v);
^^^
Change in other lines too.

> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>&
bottom);
> std::vector<string> hcat (const vector<string>& left, const
vector<string>& right);
>
> #endif
>
>

Sharad

Victor Bazarov

unread,
Dec 3, 2004, 6:33:01 AM12/3/04
to
Francis wrote:
> Can anybody help me with this code ? I contains errors I don't understand.
> I use Visual Studio C++ 6.0, Service Pack 6.
>
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>
> std::string::size_type width (const std::vector<string>& v);

std::string::size_type width(const std::vector<std::string>& v);

and so on...

> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>& bottom);
> std::vector<string> hcat (const vector<string>& left, const vector<string>& right);
>
> #endif
>
>
> ERROR REPORT
> ============
> error C2065: 'string' : undeclared identifier
> error C2143: syntax error : missing ',' before '<'
> error C2059: syntax error : '<'


V

Woodstok

unread,
Dec 3, 2004, 6:30:11 AM12/3/04
to

"Francis" <francis...@hotmail.com> wrote in message
news:71714e61.04120...@posting.google.com...

> Can anybody help me with this code ? I contains errors I don't understand.
> I use Visual Studio C++ 6.0, Service Pack 6.
>
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>
> std::string::size_type width (const std::vector<string>& v);
> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>&
> bottom);
> std::vector<string> hcat (const vector<string>& left, const
> vector<string>& right);
>
> #endif
>
>
> ERROR REPORT
> ============
> error C2065: 'string' : undeclared identifier
> error C2143: syntax error : missing ',' before '<'
> error C2059: syntax error : '<'
>

Wherever you reference vector or string types, you will need to scope them
to the std namespace. You've done this in some cases but certainly not all.

try:

#ifndef framing_h
#define framing_h

#include <vector>
#include <string>

std::string::size_type width (const std::vector<std::string>& v);
std::vector<std::string> frame (const std::vector<std::string>& v);
std::vector<std::string> vcat (const std::vector<std::string>& top, const
std::vector<std::string>& bottom);
std::vector<std::string> hcat (const std::vector<std::string>& left, const
std::vector<std::string>& right);

#endif

An alternative solution would be to add 'using namespace std' to above the
function definitions, however I'm allergic to 'using namespace' statements
in header files.

Woodstok

Francis Glassborow

unread,
Dec 3, 2004, 9:28:20 AM12/3/04
to
In article <71714e61.04120...@posting.google.com>, Francis
<francis...@hotmail.com> writes

>Can anybody help me with this code ? I contains errors I don't understand.
>I use Visual Studio C++ 6.0, Service Pack 6.
>
>CODE (header file)
>====
>#ifndef framing_h
>#define framing_h
>
>#include <vector>
>#include <string>

Insert:

using std::string;
using std::vector;

or explicitly qualify _all_ uses of string and vector

>
>std::string::size_type width (const std::vector<string>& v);
>std::vector<string> frame (const vector<string>& v);
>std::vector<string> vcat (const vector<string>& top, const vector<string>& bottom);
>std::vector<string> hcat (const vector<string>& left, const vector<string>& right);
>
>#endif
>
>
>ERROR REPORT
>============
>error C2065: 'string' : undeclared identifier
>error C2143: syntax error : missing ',' before '<'
>error C2059: syntax error : '<'

--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects

Thomas Maeder

unread,
Dec 3, 2004, 9:31:50 AM12/3/04
to
francis...@hotmail.com (Francis) writes:

> Can anybody help me with this code ? I contains errors I don't understand.
> I use Visual Studio C++ 6.0, Service Pack 6.
>
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>
> std::string::size_type width (const std::vector<string>& v);

At the start of this line, you correctly write std::string, but not the
second time "string" occurs on the line.


> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>& bottom);
> std::vector<string> hcat (const vector<string>& left, const vector<string>& right);

More unqualified string usages here; what do you get if you change each to
std::string?

Antoun Kanawati

unread,
Dec 3, 2004, 9:26:41 AM12/3/04
to
Francis wrote:
> Can anybody help me with this code ? I contains errors I don't understand.
> I use Visual Studio C++ 6.0, Service Pack 6.
>
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>
> std::string::size_type width (const std::vector<string>& v);
> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>& bottom);
> std::vector<string> hcat (const vector<string>& left, const vector<string>& right);
>
> #endif
>
>
> ERROR REPORT
> ============
> error C2065: 'string' : undeclared identifier
> error C2143: syntax error : missing ',' before '<'
> error C2059: syntax error : '<'

You're missing a whole bunch of std::'s in front of a whole bunch of
identifiers.
--
A. Kanawati
NO.anto...@comcast.net

Randy Maddox

unread,
Dec 3, 2004, 9:52:46 AM12/3/04
to
francis...@hotmail.com (Francis) wrote in message news:<71714e61.04120...@posting.google.com>...

> Can anybody help me with this code ? I contains errors I don't understand.
> I use Visual Studio C++ 6.0, Service Pack 6.
>
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>
> std::string::size_type width (const std::vector<string>& v);
> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>& bottom);
> std::vector<string> hcat (const vector<string>& left, const vector<string>& right);
>
> #endif
>
>
> ERROR REPORT
> ============
> error C2065: 'string' : undeclared identifier
> error C2143: syntax error : missing ',' before '<'
> error C2059: syntax error : '<'
>

Try replacing all uses of unadorned "string" with "std::string".

Randy.

Francis

unread,
Dec 3, 2004, 12:07:44 PM12/3/04
to
I found the solution myself. Forgot the std:: a couple of times..

Manuel Peinado

unread,
Dec 3, 2004, 9:39:08 AM12/3/04
to
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>
> std::string::size_type width (const std::vector<string>& v);
> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>&
bottom);
> std::vector<string> hcat (const vector<string>& left, const
vector<string>& right);
>
> #endif
>
>
> ERROR REPORT
> ============
> error C2065: 'string' : undeclared identifier
> error C2143: syntax error : missing ',' before '<'
> error C2059: syntax error : '<'
>

std::string::size_type width (const std::vector<std::string>& v);


std::vector<std::string> frame (const std::vector<std::string>& v);
std::vector<std::string> vcat (const std::vector<std::string>& top, const
std::vector<std::string>& bottom);
std::vector<std::string> hcat (const std::vector<std::string>& left, const
std::vector<std::string>& right);

[ See http://www.gotw.ca/resources/clcm.htm for info about ]

Gerhard Menzl

unread,
Dec 3, 2004, 9:35:27 AM12/3/04
to
Francis wrote:

> Can anybody help me with this code ? I contains errors I don't understand.
> I use Visual Studio C++ 6.0, Service Pack 6.
>
> CODE (header file)
> ====
> #ifndef framing_h
> #define framing_h
>
> #include <vector>
> #include <string>
>
> std::string::size_type width (const std::vector<string>& v);
> std::vector<string> frame (const vector<string>& v);
> std::vector<string> vcat (const vector<string>& top, const vector<string>& bottom);
> std::vector<string> hcat (const vector<string>& left, const vector<string>& right);
>
> #endif
>
>
> ERROR REPORT
> ============
> error C2065: 'string' : undeclared identifier
> error C2143: syntax error : missing ',' before '<'
> error C2059: syntax error : '<'

You have omitted the std:: qualifier in numerous places before string
and vector. If you change the above to

std::string::size_type width (const std::vector<std::string>& v);
std::vector<std::string> frame (const std::vector<std::string>& v);
std::vector<std::string> vcat (const std::vector<std::string>& top,

const std::vector<std::string>& bottom);


std::vector<std::string> hcat (const std::vector<std::string>& left,
const std::vector<std::string>& right);

the errors will disappear. If you think this is cumbersome, you are
right. One way around this is to use using declarations:

using std::string;
using std::vector;

This allows you to drop all std:: qualifications in the above code. The
downside of it is that you import the names string and vector into the
global namespace for all clients that include your header. Better still
is to use typedefs:

typedef std::string::sizetype text_size;
typedef std::vector<std::string> text_collection;

These names are just suggestions; use whatever makes sense in your
context. Not only does this reduce the clutter considerably:

text_size width (const text_collection& v);
text_collection frame (const text_collection& v);
text_collection vcat (const text_collection& top,
const text_collection& bottom);
text_collection hcat (const text_collection& left,
const text_collection& right);

it also makes it much easier to change the underlying container if need
arises.

--
Gerhard Menzl

#dogma int main ()

Humans may reply by replacing the obviously faked part of my e-mail
address with "kapsch".

0 new messages