473,785 Members | 2,824 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 #1
13 1885
"Dave" <be***********@ yahoo.com> wrote in message
news:vv******** ****@news.super news.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::si ze_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******@u senet.per.parad ox.net.au...
"Dave" <be***********@ yahoo.com> wrote in message
news:vv******** ****@news.super news.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::si ze_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::ChangeSal e()
{
std::string::si ze_type first_char;
std::string::si ze_type idx;
std::string::si ze_type last_char;
int num_tabs;
std::string one_line;
std::string percent;
int total(0);

for (int i = 0; i < mVisibleMatchUp s_psxListBox->count(); ++i)
{
one_line = std::string(mVi sibleMatchUps_p sxListBox->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());

}

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

"Dave" <be***********@ yahoo.com> wrote in message news:vv******** ****@news.super news.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.newshosti ng.com...

"Dave" <be***********@ yahoo.com> wrote in message news:vv******** ****@news.super news.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.super news.com...

"Ron Natalie" <ro*@sensor.com > wrote in message
news:3f******** *************** @news.newshosti ng.com...

"Dave" <be***********@ yahoo.com> wrote in message news:vv******** ****@news.super news.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******@spaml ess.rochester.r r.com> wrote in message
news:DJ******** ***********@twi ster.nyroc.rr.c om...
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******@comca st.net> wrote in message news:6d******** ************@co mcast.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******** ***********@nwr ddc02.gnilink.n et...
"Cy Edmunds" <ce******@spaml ess.rochester.r r.com> wrote in message
news:DJ******** ***********@twi ster.nyroc.rr.c om...
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

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

Similar topics

10
8184
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
9201
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
15903
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
2903
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
23220
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
10676
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
10324
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
10147
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...
1
10090
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
9949
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
8971
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
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
5380
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
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.