473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1631
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.public.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.public.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
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...
10
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...
24
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...
6
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
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)...
12
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
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&...
84
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
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 "" //...
5
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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,...
0
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...
0
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,...

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.