473,327 Members | 1,952 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,327 software developers and data experts.

Stupid Question #119

OK, why doesn't this work:
string EraseCommas(string &numericString)
{
UINT16_T commaPosition;

commaPosition = numericString.find(",");
while (commaPosition != string::npos);
{
numericString.erase(commaPosition);
commaPosition = numericString.find(",", commaPosition);
}

return numericString;
}
istringstream(EraseCommas(description.substr(begIn dex, endIndex - begIndex + 1))) >> population;
compiles with

make -f import.mak TARGET=pc
g++ -c -DTARGET_PC -Wall -g -I /. -I /mingw/include/ -I /devstudio/vc/include -o ./pc/import.o -Wno-deprecated import.cpp
import.cpp: In member function `virtual bool COUNTY::parseObject(BOOK&)':
import.cpp:213: parse error before `>>' token
make: *** [pc/import.o] Error 1

Compilation exited abnormally with code 2 at Sun Oct 17 21:23:41

--
% Randy Yates % "And all that I can do
%% Fuquay-Varina, NC % is say I'm sorry,
%%% 919-577-9882 % that's the way it goes..."
%%%% <ya***@ieee.org> % Getting To The Point', *Balance of Power*, ELO
http://home.earthlink.net/~yatescr
Jul 22 '05 #1
7 1333
Randy Yates schrieb:
OK, why doesn't this work:
string EraseCommas(string &numericString) this way it can take a temporary, like description.substr(...) below:
string EraseCommas(const string &numericString) { see above, and replace all occurances of numericString with result below:
string result = numericString; UINT16_T commaPosition; UINT16_T (some user-defined 16-bit unsigned type?) might very well not
be large enough for string::npos...:
string::size_type commaPosition;

commaPosition = numericString.find(",");
while (commaPosition != string::npos); ^ oops, empty endless loop :-) {
numericString.erase(commaPosition); erase one char, not everything from the comma till the end:
numericString.erase(commaPosition, 1); commaPosition = numericString.find(",", commaPosition);
}

return numericString;
}
istringstream(EraseCommas(description.substr(begIn dex, endIndex - begIndex + 1))) >> population;
compiles with

make -f import.mak TARGET=pc
g++ -c -DTARGET_PC -Wall -g -I /. -I /mingw/include/ -I /devstudio/vc/include -o ./pc/import.o -Wno-deprecated import.cpp
import.cpp: In member function `virtual bool COUNTY::parseObject(BOOK&)':
import.cpp:213: parse error before `>>' token


Yep :-(
This line:
istringstream(EraseCommas(description.substr(begIn dex, endIndex -
begIndex + 1))) >> population;
is parsed as a function declaration followed by >> population
unfortunately. This one works:
istringstream is(EraseCommas(description.substr(begIndex, endIndex -
begIndex + 1)));
is >> population;

Regards,
Malte
Jul 22 '05 #2
Malte Starostik <ma*************@t-online.de> writes:
Randy Yates schrieb:
OK, why doesn't this work:
string EraseCommas(string &numericString)

this way it can take a temporary, like description.substr(...) below:
string EraseCommas(const string &numericString)
{

see above, and replace all occurances of numericString with result below:
string result = numericString;


But, at the risk of being overly anal, that's not what I want to accomplish.
I'd like EraseCommas(numericString) to operate either as a stand-along function
that operates on numericString,
string numericString;
EraseCommas(numericString);

or as a string

string line;
string numericString;
line = EraseCommas(numericString);

But thanks much for the help, Malte.

--Randy

UINT16_T commaPosition;

UINT16_T (some user-defined 16-bit unsigned type?) might very well not
be large enough for string::npos...:
string::size_type commaPosition;
commaPosition = numericString.find(",");
while (commaPosition != string::npos);

^ oops, empty endless loop :-)
{
numericString.erase(commaPosition);

erase one char, not everything from the comma till the end:
numericString.erase(commaPosition, 1);
commaPosition = numericString.find(",", commaPosition);
}
return numericString;
} istringstream(EraseCommas(description.substr(begIn dex,
endIndex - begIndex + 1))) >> population;
compiles with make -f import.mak TARGET=pc g++ -c -DTARGET_PC -Wall
-g -I /. -I /mingw/include/ -I /devstudio/vc/include -o
./pc/import.o -Wno-deprecated import.cpp import.cpp: In member
function `virtual bool COUNTY::parseObject(BOOK&)':
import.cpp:213: parse error before `>>' token


Yep :-(
This line:
istringstream(EraseCommas(description.substr(begIn dex, endIndex -
begIndex + 1))) >> population;
is parsed as a function declaration followed by >> population
unfortunately. This one works:
istringstream is(EraseCommas(description.substr(begIndex, endIndex -
begIndex + 1)));
is >> population;

Regards,
Malte


--
% Randy Yates % "Though you ride on the wheels of tomorrow,
%% Fuquay-Varina, NC % you still wander the fields of your
%%% 919-577-9882 % sorrow."
%%%% <ya***@ieee.org> % '21st Century Man', *Time*, ELO
http://home.earthlink.net/~yatescr
Jul 22 '05 #3
Randy Yates wrote:
OK, why doesn't this work:


[snip]

It occured to me that someone else may have had this problem before
and solved it.

I used Google

http://www.google.com/

to search for

+"C++" +"embedded commas" +"number"

and I found lots of stuff including

http://www.roguewave.com/support/doc...rwdecimal.html
Jul 22 '05 #4
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> writes:
Randy Yates wrote:
OK, why doesn't this work:


[snip]

It occured to me that someone else may have had this problem before
and solved it.

I used Google

http://www.google.com/

to search for

+"C++" +"embedded commas" +"number"

and I found lots of stuff including

http://www.roguewave.com/support/doc...rwdecimal.html


Yeah, I found a lot of "stuff" too. Just like Walmart...
--
% Randy Yates % "Bird, on the wing,
%% Fuquay-Varina, NC % goes floating by
%%% 919-577-9882 % but there's a teardrop in his eye..."
%%%% <ya***@ieee.org> % 'One Summer Dream', *Face The Music*, ELO
http://home.earthlink.net/~yatescr
Jul 22 '05 #5
Randy Yates wrote:
Malte Starostik <ma*************@t-online.de> writes:
Randy Yates schrieb:
OK, why doesn't this work:
string EraseCommas(string &numericString)

this way it can take a temporary, like description.substr(...) below:
string EraseCommas(const string &numericString)
{

see above, and replace all occurances of numericString with result below:
string result = numericString;


But, at the risk of being overly anal, that's not what I want to
accomplish. I'd like EraseCommas(numericString) to operate either as a
stand-along function that operates on numericString,
string numericString;
EraseCommas(numericString);

or as a string

string line;
string numericString;
line = EraseCommas(numericString);


It will always operate on numericString. This second example will first
modify numericString, then copy it into line. In fact, your function will
always copy numericString. The first example just ignores that copy.

Jul 22 '05 #6
Malte Starostik wrote:
OK, why doesn't this work:

string EraseCommas(string &numericString)

g++ -c -DTARGET_PC -Wall -g -I /. -I /mingw/include/ -I /devstudio/vc/include -o ./pc/import.o -Wno-deprecated import.cpp
import.cpp: In member function `virtual bool COUNTY::parseObject(BOOK&)':
import.cpp:213: parse error before `>>' token


istringstream(EraseCommas(description.substr(begIn dex, endIndex -
begIndex + 1))) >> population;
is parsed as a function declaration followed by >> population
unfortunately.


How is that a function declaration? What's its name and parameter types?
It compiles just fine for me (see code below).

Maybe the OP had an error elsewhere (the error message talks
about a function COUNTY::parseObject(BOOK&) but the posted code
did not include such a function, perhaps he has an extra bracket
on the previous line or something.

#include <string>
#include <sstream>

using std::istringstream;
using std::string;

string EraseCommas(string &numericString);

int main()
{
string description;
int begIndex, endIndex, population;

istringstream(EraseCommas(description.substr(begIn dex, endIndex -
begIndex + 1))) >> population;
}
Jul 22 '05 #7
Old Wolf wrote:
Malte Starostik wrote:
> OK, why doesn't this work:
>
> string EraseCommas(string &numericString)
>
> g++ -c -DTARGET_PC -Wall -g -I /. -I /mingw/include/ -I
> /devstudio/vc/include -o ./pc/import.o -Wno-deprecated import.cpp
> import.cpp: In member function `virtual bool
> COUNTY::parseObject(BOOK&)': import.cpp:213: parse error before `>>'
> token
istringstream(EraseCommas(description.substr(begIn dex, endIndex -
begIndex + 1))) >> population;
is parsed as a function declaration followed by >> population
unfortunately.


How is that a function declaration? What's its name and parameter types?


Actually, I think it's not a function declaration, but instead the
definition of an object of type istringstream with name EraseCommas, i.e.
the same as:

istringstream EraseCommas(description.substr(begIndex, endIndex -
begIndex + 1)) >> population;

And you cannot define a named object and directly use operator>> on it.
After splitting it up, it compiles here, too:

istringstream(EraseCommas(description.substr(begIn dex, endIndex -
begIndex + 1)));

EraseCommas >> population;
It compiles just fine for me (see code below).
Really?
Maybe the OP had an error elsewhere (the error message talks
about a function COUNTY::parseObject(BOOK&) but the posted code
did not include such a function, perhaps he has an extra bracket
on the previous line or something.
I rather think that the erroneous line actually is part of that function in
the OP's original code.

#include <string>
#include <sstream>

using std::istringstream;
using std::string;

string EraseCommas(string &numericString);

int main()
{
string description;
int begIndex, endIndex, population;

istringstream(EraseCommas(description.substr(begIn dex, endIndex -
begIndex + 1))) >> population;
}


That code produces the same error message as the OP's code here.

Jul 22 '05 #8

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

Similar topics

8
by: sebb | last post by:
I'm kind of newbie to programming, but I thought of something and I want some opinions on that. It's about a new instruction block to do some cycles. I thought about that because it's not very...
119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
2
by: Lampa Dario | last post by:
Hi, where is this stupid error in this program? When I execute it, i receive a segmentation fault error. #include <stdio.h> int main(int argc, char *argv, char *env) { int i=0; int l=0; int...
10
by: Fei Li | last post by:
Hi, If I'm not stupid for this, then the design of FolderBrowserDialog is very stupid. It only allow to strat browing from several predefined folder(Environment.SpecialFolder). What can I do if...
5
by: Guoqi Zheng | last post by:
I think I have this kind of problem very often, now it is really making me crazy. VS.NET always want to change my html code. Ok, that is fine as long as Vs.Net can ask my confirmaton first. For...
6
by: Adam Smith | last post by:
I have posted this and similar questions repeatedly and can't even raise a single response. I am being led to believe that this then 'Must be a stupid question' although people say that there is no...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.