473,811 Members | 3,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

std::string with non-type template arg

I received some code from another programmer who happens to be out of
town. In this, he had something like:

struct st
{
std::string s<20>;
};

Looks like it's setting the string size.

VC++ 6 produced an error in compilation, complaining of a syntax error
before the <20> part. I looked at Stroustrup and Josuttis to see if I
could find something about a non-type template argument for doing this,
and didn't really see anything, although I may have just not realized I
was seeing it. I didn't see any examples similar to this either.

Normally when I want to specify string size at declaration, I use the
constructor:

std::string s(20, 0);
Presumably this guy had compiled it on whatever platform he uses
without problem, although I can't check with him. Is this an error on
his part, or yet another VC++ template problem?


Brian
Aug 4 '05 #1
2 1648
Default User wrote:
I received some code from another programmer who happens to be out of
town. In this, he had something like:

struct st
{
std::string s<20>;
};

Looks like it's setting the string size.

VC++ 6 produced an error in compilation, complaining of a syntax error
before the <20> part. I looked at Stroustrup and Josuttis to see if I
could find something about a non-type template argument for doing this,
and didn't really see anything, although I may have just not realized I
was seeing it. I didn't see any examples similar to this either.

Normally when I want to specify string size at declaration, I use the
constructor:

std::string s(20, 0);
Presumably this guy had compiled it on whatever platform he uses
without problem, although I can't check with him. Is this an error on
his part, or yet another VC++ template problem?


The code presented isn't C++. As to VC++, ask in
microsoft.publi c.vc.language.

V
Aug 4 '05 #2
Victor Bazarov wrote:

The code presented isn't C++.
That's all I needed to know.
As to VC++, ask in microsoft.publi c.vc.language.


As it seems to be correctly diagnosing a syntax error, that doesn't
seem needful.


Brian

Aug 4 '05 #3

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

Similar topics

19
22747
by: Espen Ruud Schultz | last post by:
Lets say I have a char pointer and an std::string. Is it possible to get a pointer to the std::string's "content" so that the char pointer can point to the same text? And vice versa; can I give the std::string a pointer and a length and then give the std::string control over the pointer and its content? I'm basically trying to avoid copying large text between an std::string and a char pointer, and vice versa. Is there anyhing in the...
10
8199
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 effectively impossible to forward declare std::string. (Yes I am aware that some libraries have a string_fwd.h header, but this is not portable.) That said, is there any real reason why I can't derive an otherwise empty
24
11041
by: Julie | last post by:
I'm re-evaluating the way that I convert from a std::string to char *. (Requirement: the source is a std::string, the usable contents are char *) Here is what I've come up with: #include <string> #include <vector> #include <cstring> // presume s from somewhere, such as:
6
2621
by: Kian Goh | last post by:
Hello, I would like to replace all the occurrence of "(" and ")" in C++ std::string to "\(" and "\)". For example: string s = "(abc)|(toto)|(lala)" will be become "\(abc\)|\(toto\)|\(lala\)"
5
8758
by: Peter Jansson | last post by:
Hello, I have the following code: std::map<int,std::set<std::string> > k; k="1234567890"; k="2345678901"; //... std::set<std::string> myMethod(std::map<int,std::set<std::string> > k) throw(std::runtime_error)
12
3158
by: Vincent RICHOMME | last post by:
Hi, I am currently implementing some basic classes from .NET into modern C++. And I would like to know if someone would know a non mutable string class.
3
8371
by: Pierre Barbier de Reuille | last post by:
Hi, I was wondering why there was no predefine operator<< puting a std::string into a std::wostream. The strangest is that something similar to this would work: std::wostream& operator<<(std::wostream& stream, std::string str) { stream << str.c_str(); return stream;
84
15928
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; };
11
2906
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 "" // 'words' are any sequences of non-whitespace characters // leading, trailing and multiple whitespace characters // should be ignored.
5
4577
by: Ramesh | last post by:
Hi. Assuming I have a code snippet like below: #include <iostream> using namespace std; char Mac = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5 }; std::string csMac;
0
9730
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
9605
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,...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
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
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4341
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
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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.