473,473 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Create 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::size_type idx;
std::string one_line;
..
..
..
idx = one_line.find('\t', 0);
error C2059: syntax error : 'constant'
Jul 22 '05 #1
13 1857
"Dave" <be***********@yahoo.com> wrote in message
news:vv************@news.supernews.com
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::size_type idx;
std::string one_line;
.
.
.
idx = one_line.find('\t', 0);
error C2059: syntax error : 'constant'

Try supplying a complete compileable sample that produces the error. The
three lines you have supplied compile fine with both VC++ 2002 and Comeau
online.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #2

"John Carson" <do***********@datafast.net.au> wrote in message
news:3f******@usenet.per.paradox.net.au...
"Dave" <be***********@yahoo.com> wrote in message
news:vv************@news.supernews.com
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::size_type idx;
std::string one_line;
.
.
.
idx = one_line.find('\t', 0);
error C2059: syntax error : 'constant'

Try supplying a complete compileable sample that produces the error. The
three lines you have supplied compile fine with both VC++ 2002 and Comeau
online.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)


I don't know if this will help, but here's the full function. However, to
provide enough context to make it fully compileable would draw in thousands
of lines of code. So, this is the best I can do, but I understand if it's
not enough context and doesn't help... (BTW my platform is VC++ 7.1, but I
suppose that shouldn't matter; famous last words...)

void Sell::ChangeSale()
{
std::string::size_type first_char;
std::string::size_type idx;
std::string::size_type last_char;
int num_tabs;
std::string one_line;
std::string percent;
int total(0);

for (int i = 0; i < mVisibleMatchUps_psxListBox->count(); ++i)
{
one_line = std::string(mVisibleMatchUps_psxListBox->text(i));
num_tabs = std::count(one_line.begin(), one_line.end(), '\t');

if (num_tabs < 7)
continue;

idx = one_line.find('\t', 0);
first_char = idx + 1;
last_char = one_line.find('\t', first_char) - 1;

if (last_char < first_char)
continue;

percent = one_line.substr(first_char, last_char - first_char + 1);
total += atoi(percent.c_str());

}

mVisibleMatchUps_psxListBox->storeData() ;
DeleteSale() ;
AddSale() ;
}//ChangeSale(...
Jul 22 '05 #3

"Dave" <be***********@yahoo.com> wrote in message news:vv************@news.supernews.com...
]> .
idx = one_line.find('\t', 0);

Try sticking an #undef find before this line. The line looks fine, could be some joker
redefined find.

Jul 22 '05 #4

"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

"Dave" <be***********@yahoo.com> wrote in message news:vv************@news.supernews.com... ]> .
idx = one_line.find('\t', 0);
Try sticking an #undef find before this line. The line looks fine,

could be some joker redefined find.


$%&#^!*#$#*!$& (repeat 100 times)!!!!!

That actually was the problem! Man, I could just scream trying to maintain
the code base for the project I'm on. This is the most God-awful piece of
programming I've ever seen, and there are 300,000 lines of this nonsense!
The programmers that did this and the managers that allowed this and
everything else that's wrong with this app. to happen should all be
summarily executed...

Thanks, I think you just saved my sanity! (But it's doomed eventually anyway
since I'll have to continue to work on this project!)
Jul 22 '05 #5
"Dave" <be***********@yahoo.com> wrote in message
news:vv************@news.supernews.com...

"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

"Dave" <be***********@yahoo.com> wrote in message news:vv************@news.supernews.com...
]> .
idx = one_line.find('\t', 0);

Try sticking an #undef find before this line. The line looks fine,

could be some joker
redefined find.


$%&#^!*#$#*!$& (repeat 100 times)!!!!!

That actually was the problem! Man, I could just scream trying to maintain
the code base for the project I'm on. This is the most God-awful piece of
programming I've ever seen, and there are 300,000 lines of this nonsense!
The programmers that did this and the managers that allowed this and
everything else that's wrong with this app. to happen should all be
summarily executed...

Thanks, I think you just saved my sanity! (But it's doomed eventually

anyway since I'll have to continue to work on this project!)


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?

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #6
Dave wrote:
"Ron Natalie" <ro*@sensor.com> wrote
"Dave" <be***********@yahoo.com> wrote
idx = one_line.find('\t', 0);
Try sticking an #undef find before this line. The line looks fine,
could be some joker redefined find.

$%&#^!*#$#*!$& (repeat 100 times)!!!!!

That actually was the problem!


Okay, *that's* impressive.

Ron, are you actually the author of the dubious code in question?

;),
Jeff

Jul 22 '05 #7
"Cy Edmunds" <ce******@spamless.rochester.rr.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
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #8

"Jeff Schwab" <je******@comcast.net> wrote in message news:6d********************@comcast.com...
Dave wrote:
"Ron Natalie" <ro*@sensor.com> wrote
"Dave" <be***********@yahoo.com> wrote
idx = one_line.find('\t', 0);

Try sticking an #undef find before this line. The line looks fine,
could be some joker redefined find.

$%&#^!*#$#*!$& (repeat 100 times)!!!!!

That actually was the problem!


Okay, *that's* impressive.

Ron, are you actually the author of the dubious code in question?


Nope, I looked up the error in the Microsoft docs. Then I thought about how the
above syntax could gag on the '\t' or 0 literals and the only way I could think of was
if find() were NOT a function.

Jul 22 '05 #9
"P.J. Plauger" <pj*@dinkumware.com> wrote in message
news:UH*******************@nwrddc02.gnilink.net...
"Cy Edmunds" <ce******@spamless.rochester.rr.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
Dinkumware, Ltd.
http://www.dinkumware.com


Absolutely no argument here.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #10
Cy Edmunds wrote:
"P.J. Plauger" <pj*@dinkumware.com> wrote in message
news:UH*******************@nwrddc02.gnilink.net...
"Cy Edmunds" <ce******@spamless.rochester.rr.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
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******@comcast.net> wrote in message
news:jL********************@comcast.com...
Cy Edmunds wrote:
"P.J. Plauger" <pj*@dinkumware.com> wrote in message
news:UH*******************@nwrddc02.gnilink.net...
"Cy Edmunds" <ce******@spamless.rochester.rr.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
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******@comcast.net> wrote in message
news:jL********************@comcast.com...
Cy Edmunds wrote:
"P.J. Plauger" <pj*@dinkumware.com> wrote in message
news:UH*******************@nwrddc02.gnilink.net ...
"Cy Edmunds" <ce******@spamless.rochester.rr.com> wrote in message
news:DJ*******************@twister.nyroc.rr.co m...

>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...


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******@comcast.net> wrote in message
news:lN********************@comcast.com...
Cy Edmunds wrote:
"Jeff Schwab" <je******@comcast.net> wrote in message
news:jL********************@comcast.com...
Cy Edmunds wrote:

"P.J. Plauger" <pj*@dinkumware.com> wrote in message
news:UH*******************@nwrddc02.gnilink.net ...
>"Cy Edmunds" <ce******@spamless.rochester.rr.com> wrote in message
>news:DJ*******************@twister.nyroc.rr.co m...
>
>
>
>>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...


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 "personality" 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
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...
11
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(...
8
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...
6
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...
2
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
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 "" //...
29
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...
6
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
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
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,...
0
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...
1
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...
0
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...
0
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,...
0
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...
0
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 ...
0
muto222
php
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.