473,769 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"using namespace std" in VS C++ Class Library (.NET) project

When I create a new C++ project of type "Class Library (.NET)", I am
unable to then add the following line of code :
using namespace std

If I do, I get the following error on compilation :
c:\Research\Cod e\Visual Studio\TestC++2 \TestC++2.h(7): error
C2871: 'std' : a namespace with this name does not exist

If I try this with other project types, e.g. "Console Application
(.NET)" projects, I have no such problem.

Any ideas on what I can do to fix this (as I would like to use
functions from <string.h> in my code).

Thanks,

Alex.
Nov 17 '05 #1
6 4526
AlexD_UK wrote:
When I create a new C++ project of type "Class Library (.NET)", I am
unable to then add the following line of code :
using namespace std

If I do, I get the following error on compilation :
c:\Research\Cod e\Visual Studio\TestC++2 \TestC++2.h(7): error
C2871: 'std' : a namespace with this name does not exist

If I try this with other project types, e.g. "Console Application
(.NET)" projects, I have no such problem.

Any ideas on what I can do to fix this (as I would like to use
functions from <string.h> in my code).
Use #include<string > rather than <string.h>

Thanks,

Alex.

--
Jacobo Rodríguez Villar

TyphoonLabs Lead Programmer

http://www.typhoonlabs.com
Nov 17 '05 #2

"Jacobo Rodriguez Villar" <skdjf@sdkjf> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
AlexD_UK wrote:
When I create a new C++ project of type "Class Library (.NET)", I am
unable to then add the following line of code :
using namespace std

If I do, I get the following error on compilation :
c:\Research\Cod e\Visual Studio\TestC++2 \TestC++2.h(7): error
C2871: 'std' : a namespace with this name does not exist

If I try this with other project types, e.g. "Console Application
(.NET)" projects, I have no such problem.

Any ideas on what I can do to fix this (as I would like to use
functions from <string.h> in my code).


Use #include<string > rather than <string.h>

Thanks,

Alex.

--
Jacobo Rodríguez Villar

TyphoonLabs Lead Programmer

http://www.typhoonlabs.com

Actually, #include <string> will get you the C++ string class, not what is
in <string.h>.
What you want is

#include <cstring>

which is the c++ equivalent of string.h

Nov 17 '05 #3
Thanks to you both.

When I try the first option with new Class Library (.NET) project and
the following code :

// TestC5.h
#pragma once
#include <string>
using namespace System;

namespace TestC5
{
public __gc class Class1
{
};

void method(void)
{
char str1[]= "To be or not to be";
char str2[6];
strncpy (str2,str1,5);
}
}

I get this error :
TestC++5 error LNK2020: unresolved token (0A000006) _CxxThrowExcept ion
TestC++5 error LNK2020: unresolved token (0A000017) delete

If I substitute for #include <cstring>, I get :
TestC++5 error LNK2001: unresolved external symbol "char * __cdecl
strncpy(char *,char const *,unsigned int)"
(?strncpy@@$$J0 YAPADPADPBDI@Z)
Am I missing another import library?

Alex.
Nov 17 '05 #4
Nope, strncpy is in the runtime, not import libraries
--
cheers,
Costea Bogdan
"AlexD_UK" wrote:
Thanks to you both.

When I try the first option with new Class Library (.NET) project and
the following code :

// TestC5.h
#pragma once
#include <string>
using namespace System;

namespace TestC5
{
public __gc class Class1
{
};

void method(void)
{
char str1[]= "To be or not to be";
char str2[6];
strncpy (str2,str1,5);
}
}

I get this error :
TestC++5 error LNK2020: unresolved token (0A000006) _CxxThrowExcept ion
TestC++5 error LNK2020: unresolved token (0A000017) delete

If I substitute for #include <cstring>, I get :
TestC++5 error LNK2001: unresolved external symbol "char * __cdecl
strncpy(char *,char const *,unsigned int)"
(?strncpy@@$$J0 YAPADPADPBDI@Z)
Am I missing another import library?

Alex.

Nov 17 '05 #5
Costea,

Thanks - so can you think of any reason why my project is not
compiling?

Do I need to use a different version of the runtime to the one that I
am given by default when creating a VS C++ Class Library (.NET)
project?

Alex.

"Costea Bogdan bcostea.ro>" <bogdan<at> wrote in message news:<42******* *************** ************@mi crosoft.com>...
Nope, strncpy is in the runtime, not import libraries
--
cheers,
Costea Bogdan

Nov 17 '05 #6

"AlexD_UK" <al*********@ho tmail.com> wrote in message
news:e3******** *************** ***@posting.goo gle.com...
When I try the first option with new Class Library (.NET) project and
the following code :

// TestC5.h
#pragma once
#include <string>
using namespace System;

namespace TestC5
{
public __gc class Class1
{
};

void method(void)
{
char str1[]= "To be or not to be";
char str2[6];
strncpy (str2,str1,5);
}
}

I get this error :
TestC++5 error LNK2020: unresolved token (0A000006) _CxxThrowExcept ion
TestC++5 error LNK2020: unresolved token (0A000017) delete


strncpy is part of the <cstring> header of the std namespace, not System
namespace which is part of the .net <mscorlib.dll >. Also, you need to make
sure you allocate enough n characters in strncpy(str2, str1, n) or it will
truncate. n needs to allocate enough room for the string plus the null
character at the end.

Just using standard c++, here's how I would rewrite and compile the code:

#include <cstring>
#include <iostream>
using namespace std;

int main()
{
const char str1[] = "To be or not to be";
char str2[24];
strncpy(str2,st r1,23);

cout << str1 << endl;
cout << str2 << endl;
}

I do though, get this warning when compiling with VS.NET 8.0 beta:

cstrcpy.cpp(9) : warning C4996: 'strncpy' was declared deprecated
D:\Program Files\Microsoft Visual Studio 8\VC\include\st ring.h(121)
: see declaration of 'strncpy'
Microsoft (R) Incremental Linker Version 8.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

It is unsafe and cumbersome to use C style chars. Better to use safer
standard C++ strings:

#include <iostream>
#include <string>
using namespace std;

int main()
{
string str1 = "To be or not to be";
string str2 = str1;

cout << str1 << endl;
cout << str2 << endl;
}

str1 can be as long or short as you want, and you don't have to worry about
allocating enough when copying it to str2.

- Don Kim
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1383
by: Steve Terepin | last post by:
Do I need to include some extra libraries when I use the STL <string> classes ? I've created a new Class Library (.NET) project, added a #include <string> directive to the main .cpp file, and created an instance of a std::string ; this compiles fine, but the linker reports two unresolved symbols - '_CxxThrowException' and 'delete'. Any ideas ?
2
6466
by: Phil Ten | last post by:
Hello, I am working on a .NET C++ project based on the "Class Library (.NET)" wizard of Visual Studio .NET 2003. I would like to know if my .NET component is running in a ASP.NET page (.apsx file), and if it is the case I would like to execute a specific task based on the current HTTP request.
5
1686
by: Marco Zapletal | last post by:
hi group, i am facing the following problem: i have a vs.net (c#) project, which compiles into a class library. now i wrote a kind of testcase (with a main method()) which i want to execute (and debug) from vs.net. but i found no possibility how to execute this testcase in my project... any help would be appreciated,
4
3181
by: Holly Li | last post by:
Hi, Because of reuse, I need to mix C# project and VB.net project. To illustrate the problem, I have built 3 simple projects: 1) C# library--projc (has one class "Manager") 2) vb.net library--projb (has one class "Bob") 3) vb.net web form--projweb (has one web form with a label on it) Here are the code:
2
2158
by: Rafael Pivato | last post by:
Can I have two Class Libraries to share the same root namespace ? I want something like this: MySystem (root namespace) MyBO (class library A) MyDS (class library B) MyUS (class library C)
0
908
by: Phil | last post by:
I have created a Visual C++ Class Library Project and I am using the new and delete operators to allocate and release memory. But When I try to build the Project, I receive LNK2020 error from the Linker. What Headers / Libraries do I need to include to Build this Project ? I have tried #include <new>, and linking thrownew.obj but I still get Linking Errors. Any help with this would be appreciated ...
3
2779
by: Phaitour | last post by:
Hi there, I'm working on developing a large Class Library project that is slowly becoming a shared "framework" library amongst multiple applications. As this shared library grows, I need to start thinking about ways to split this library up. In observing the .net framework, I've noticed that each major branch of the framework (eg. System.Net or System.Data) and even some of the minor branches are split up into individual dlls. When...
4
1496
by: Rainer Queck | last post by:
Hello NG, I started to build me a little class library. This library I added to a Project which also surves me to test the library. This library holds a namespace: namespace <myLib>.<some function> Now I added a extended Namespace to my library like: namespace <myLib>.<some other function>
1
1348
by: Fresno Bob | last post by:
Hi I am used to using the App_Code folder to put my DAL and BLL classes. However I want to move toward using separate dll's so I can start doing things like Unit Tests and using Sandcastle for documentation. My class library DAL project contains 4 .vb files, each one containing a single class, which maps to a DB table.This builds OK. I then create a website and add the class library project to the website. I then in the website a...
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.