I'd like to avoid typing std::string and std::vector without resorting
to the "using namespace std" directive, which will import the entire
standard namespace. Is there a way to import only selected items from
the std namespace, so to speak?
Thanks for any ideas,
cpp 7 2660
cppaddict wrote: I'd like to avoid typing std::string and std::vector without resorting to the "using namespace std" directive, which will import the entire standard namespace. Is there a way to import only selected items from the std namespace, so to speak?
Make your pick:
using std::string; // then just type 'string'
or
typedef std::string str; // then just type 'str'
Victor
cppaddict <he***@hello.com> wrote in
news:4p********************************@4ax.com: I'd like to avoid typing std::string and std::vector without resorting to the "using namespace std" directive, which will import the entire standard namespace. Is there a way to import only selected items from the std namespace, so to speak?
Thanks for any ideas, cpp
Uh...
using std::string;
using std::vector;
?
>Make your pick: using std::string; // then just type 'string'
or
typedef std::string str; // then just type 'str'
Thanks Victor.
I like the first option. Would you recommend placing it only in my
header file, or repeating it in the implementation file too, for
clarity?
cpp
cppaddict wrote: Make your pick:
using std::string; // then just type 'string'
or
typedef std::string str; // then just type 'str'
Thanks Victor.
I like the first option. Would you recommend placing it only in my header file, or repeating it in the implementation file too, for clarity?
I recommend against any 'using' directives or declarations in the header.
If you think you need them in the global scope, limit yourself to the
implementation files only. Of course, it would be best if you could
place such declarations in the same scope level where they are going to
be used. Example: if you're working with strings in a single function
in some module, no sense to put the 'using' declaration at the beginning
of the module that contains that function. Put it in the function itself.
Victor
>I recommend against any 'using' directives or declarations in the header. If you think you need them in the global scope, limit yourself to the implementation files only.
Would you object to putting "using std::string;" inside the class:
class MyClass {
using std::string;
private:
string name_;
.....
}
thanks again,
cpp
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:XI***************@newsread1.dllstx09.us.to.ve rio.net... I recommend against any 'using' directives or declarations in the header. If you think you need them in the global scope, limit yourself to the implementation files only. Of course, it would be best if you could place such declarations in the same scope level where they are going to be used. Example: if you're working with strings in a single function in some module, no sense to put the 'using' declaration at the beginning of the module that contains that function. Put it in the function itself.
Whoa! You can do that?? Awesome! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Angus Leeming |
last post by:
Hello,
Could someone explain to me why the Standard conveners chose to typedef
std::string rather than derive it from std::basic_string<char, ...>?
The result of course is that it is...
|
by: Christopher Benson-Manica |
last post by:
Let's say I have a std::string, and I want to replace all the ','
characters with " or ", i.e. "A,B,C" -> "A or B or C". Is the
following the best way to do it?
int idx;
while(...
|
by: Jason Heyes |
last post by:
Does this function need to call eof after the while-loop to be correct?
bool read_file(std::string name, std::string &s)
{
std::ifstream in(name.c_str());
if (!in.is_open())
return false;
...
|
by: Erik Wikström |
last post by:
First of all, forgive me if this is the wrong place to ask this question,
if it's a stupid question (it's my second week with C++), or if this is
answered some place else (I've searched but not...
|
by: Patrick Kowalzick |
last post by:
Dear NG,
I would like to change the allocator of e.g. all std::strings, without
changing my code. Is there a portable solution to achieve this?
The only nice solution I can think of, would be...
|
by: Nemok |
last post by:
Hi,
I am new to STD so I have some questions about std::string because I
want use it in one of my projects instead of CString.
1. Is memory set dinamicaly (like CString), can I define for...
|
by: FBergemann |
last post by:
if i compile following sample:
#include <iostream>
#include <string>
int main(int argc, char **argv)
{
std::string test = "hallo9811111z";
std::string::size_type ret;
|
by: Peter Olcott |
last post by:
Is there anyway of doing this besides making my own string from scratch?
union AnyType {
std::string String;
double Number;
};
|
by: Jacek Dziedzic |
last post by:
Hi!
I need a routine like:
std::string nth_word(const std::string &s, unsigned int n) {
// return n-th word from the string, n is 0-based
// if 's' contains too few words, return ""
//...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |