473,795 Members | 3,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inexplicable error with std::string

Can anybody tell me why the code below should produce the error below? I'm
going nuts here! Am I missing something incredibly obvious and simple?

std::string::si ze_type idx;
std::string one_line;
..
..
..
idx = one_line.find(' \t', 0);
error C2059: syntax error : 'constant'
Jul 22 '05
13 1886
Cy Edmunds wrote:
"P.J. Plauger" <pj*@dinkumware .com> wrote in message
news:UH******** ***********@nwr ddc02.gnilink.n et...
"Cy Edmunds" <ce******@spaml ess.rochester.r r.com> wrote in message
news:DJ****** *************@t wister.nyroc.rr .com...

Ron made a great call here. It goes to show you why I hate C macros so
much.

As BS once commented, they make what the compiler sees different from
what you see. How can that be good?


Maybe the compiler doesn't recognize the same dialect that you want
to speak. I agree that macros can be abused, and the OP has presented
an extreme case of such abuse. But the irony is that C++ has spawned
so many dialects over the past decade that implementors *must* make
extensive use of the preprocessor to cope.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com

Absolutely no argument here.


I didn't realize the situation was that bad. I'm sure this is a
hopelessly naive question, but... What's wrong with complying (as
closely as possible) with the most recent standard, and providing flags
for compatibility with the most common dialects?

Jul 22 '05 #11
"Jeff Schwab" <je******@comca st.net> wrote in message
news:jL******** ************@co mcast.com...
Cy Edmunds wrote:
"P.J. Plauger" <pj*@dinkumware .com> wrote in message
news:UH******** ***********@nwr ddc02.gnilink.n et...
"Cy Edmunds" <ce******@spaml ess.rochester.r r.com> wrote in message
news:DJ****** *************@t wister.nyroc.rr .com...
Ron made a great call here. It goes to show you why I hate C macros so
much.

As BS once commented, they make what the compiler sees different from
what you see. How can that be good?

Maybe the compiler doesn't recognize the same dialect that you want
to speak. I agree that macros can be abused, and the OP has presented
an extreme case of such abuse. But the irony is that C++ has spawned
so many dialects over the past decade that implementors *must* make
extensive use of the preprocessor to cope.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com

Absolutely no argument here.


I didn't realize the situation was that bad. I'm sure this is a
hopelessly naive question, but... What's wrong with complying (as
closely as possible) with the most recent standard, and providing flags
for compatibility with the most common dialects?


Nothing, if that's all there was to it. Check out the macro spaghetti at the
top of various library code (standard library, boost, etc.) and see what
these poor guys have to put up with in order to get their code to compile
across platforms and compilers. It's brutal.

I'm opposed to the preprocessor if there is any reasonable alternative but
you do what you gotta do...

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #12
Cy Edmunds wrote:
"Jeff Schwab" <je******@comca st.net> wrote in message
news:jL******** ************@co mcast.com...
Cy Edmunds wrote:
"P.J. Plauger" <pj*@dinkumware .com> wrote in message
news:UH***** **************@ nwrddc02.gnilin k.net...
"Cy Edmunds" <ce******@spaml ess.rochester.r r.com> wrote in message
news:DJ**** *************** @twister.nyroc. rr.com...

>Ron made a great call here. It goes to show you why I hate C macros so
>much.

>As BS once commented, they make what the compiler sees different from
>what you see. How can that be good?

Maybe the compiler doesn't recognize the same dialect that you want
to speak. I agree that macros can be abused, and the OP has presented
an extreme case of such abuse. But the irony is that C++ has spawned
so many dialects over the past decade that implementors *must* make
extensive use of the preprocessor to cope.

P.J. Plauger
Dinkumwar e, Ltd.
http://www.dinkumware.com


Absolutely no argument here.


I didn't realize the situation was that bad. I'm sure this is a
hopelessly naive question, but... What's wrong with complying (as
closely as possible) with the most recent standard, and providing flags
for compatibility with the most common dialects?

Nothing, if that's all there was to it. Check out the macro spaghetti at the
top of various library code (standard library, boost, etc.) and see what
these poor guys have to put up with in order to get their code to compile
across platforms and compilers. It's brutal.

I'm opposed to the preprocessor if there is any reasonable alternative but
you do what you gotta do...


I see what you mean. So, the problem isn't so much with dialects of
C++, but with portability across platforms?
Jul 22 '05 #13
"Jeff Schwab" <je******@comca st.net> wrote in message
news:lN******** ************@co mcast.com...
Cy Edmunds wrote:
"Jeff Schwab" <je******@comca st.net> wrote in message
news:jL******** ************@co mcast.com...
Cy Edmunds wrote:

"P.J. Plauger" <pj*@dinkumware .com> wrote in message
news:UH***** **************@ nwrddc02.gnilin k.net...
>"Cy Edmunds" <ce******@spaml ess.rochester.r r.com> wrote in message
>news:DJ**** *************** @twister.nyroc. rr.com...
>
>
>
>>Ron made a great call here. It goes to show you why I hate C macros so>>much.
>
>>As BS once commented, they make what the compiler sees different from
>>what you see. How can that be good?
>
>Maybe the compiler doesn't recognize the same dialect that you want
>to speak. I agree that macros can be abused, and the OP has presented
>an extreme case of such abuse. But the irony is that C++ has spawned
>so many dialects over the past decade that implementors *must* make
>extensive use of the preprocessor to cope.
>
>P.J. Plauger
>Dinkumwar e, Ltd.
>http://www.dinkumware.com
>
>
Absolutely no argument here.
I didn't realize the situation was that bad. I'm sure this is a
hopelessly naive question, but... What's wrong with complying (as
closely as possible) with the most recent standard, and providing flags
for compatibility with the most common dialects?

Nothing, if that's all there was to it. Check out the macro spaghetti at the top of various library code (standard library, boost, etc.) and see what
these poor guys have to put up with in order to get their code to compile across platforms and compilers. It's brutal.

I'm opposed to the preprocessor if there is any reasonable alternative but you do what you gotta do...


I see what you mean. So, the problem isn't so much with dialects of
C++, but with portability across platforms?


That and compilers, which have far more "personalit y" than the standard
allows. :) I guess that counts as dialects. There are other problems too,
like calling sequences, various non-standard declarations required to
compile DLL's, mumble mumble ...

I'm the wrong guy to ask though. My job doesn't really require me to get my
code to compile across a lot of platforms and compilers. It's guys like PJ
who bear the brunt of these problems.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #14

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

Similar topics

10
8185
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
11
3662
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( (idx=str.find_first_of(',')) >= 0 ) { str.replace( idx, 1, "" ); str.insert( idx, " or " ); }
8
9202
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 a namespace and another typedef to basic_string: namespace my_string {
6
11510
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 example string str1; as a class member and then add text to it. or do I have to specify it's length when defining? 2. How to convert from std::string to LPCSTR
2
5514
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;
84
15906
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
2904
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.
29
23226
by: aarthi28 | last post by:
Hi, I have written this code, and at the end, I am trying to write a vector of strings into a text file. However, my program is nor compiling, and it gives me the following error when I try to write to the file: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) I don't know what I am doing wrong. I have posted my entire program
6
10678
by: newbarker | last post by:
Hello, This program doesn't work and provides me the errror message "error C2040: 'p' : 'std::string' differs in levels of indirection from 'const char *'": #include <string> int main() {
0
9672
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
9519
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
10439
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
10215
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
10001
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...
1
7541
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...
0
5437
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.