473,406 Members | 2,745 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,406 software developers and data experts.

Funtion receiving/returning a string value..

But its not working for me.

here is my code... and I know it is something so basic that I will be
embarrassed when I am corrected.. Thanks for your patience. It compiles ok,
and I can give it a string to parse, but when I execute parse it returns
nothing... Any help is greatly appreciated.

# include <string>
# include <iostream>
using namespace std;
std::string::size_type start=0, end=0;
std::string s;
std::string wordlist;
string parse(string)
{
start = s.find_first_not_of(" .,;!?");
end = s.find_first_of(" .,;!?", start);
string wordlist( s, start, end - start );
s.erase (start, end - start);
return(wordlist);
}

int main()
{
getline(cin, s);
parse(s);
cout << wordlist;
getline(cin, s);
}
Jul 22 '05 #1
1 1178

"derrick" <ra**********@yahoo.com> wrote in message
news:Ma****************@newssvr11.news.prodigy.com ...
But its not working for me.

here is my code... and I know it is something so basic that I will be
embarrassed when I am corrected.. Thanks for your patience. It compiles ok, and I can give it a string to parse, but when I execute parse it returns
nothing... Any help is greatly appreciated.

# include <string>
# include <iostream>
using namespace std;
std::string::size_type start=0, end=0;
std::string s;
std::string wordlist;
string parse(string)
{
start = s.find_first_not_of(" .,;!?");
end = s.find_first_of(" .,;!?", start);
string wordlist( s, start, end - start );
s.erase (start, end - start);
return(wordlist);
}

int main()
{
getline(cin, s);
parse(s);
Change to:

wordlist = parse(s);
cout << wordlist;
getline(cin, s);
}


Alternatively, you can omit your 'intermediate' object and write:

cout << parse(s);

Also note that your file scope object 'wordlist' and your
function scope object 'wordlist' are two separate, unrelated
objects.

-Mike
Jul 22 '05 #2

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

Similar topics

3
by: Ye Liu | last post by:
Hi, Folks. If I have table create table t1(col1 number getnumber()) // getnumber is a funtion to generate default value of col1. How I can get this function string by a query on data...
25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
13
by: Matthias Kaeppler | last post by:
Hi, I was wondering why library implementors often make getter functions return strings by value (copies). For example, in boost::filesystem the leaf() function returns an std::string by value....
7
by: wonderboy | last post by:
Hey guys, I have a simple question. Suppose we have the following functions:- //-----My code starts here char* f1(char* s) { char* temp="Hi"; return temp;
5
by: LS | last post by:
Can a WebMethod return an Interface type? Can we pass an interface parameter ? Example : public interface IEntity { long Id { get; set; } string Name { get; set; } }
8
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
1
by: Subrato | last post by:
Hi, I am very new to xml and I have this piece of code which I took off a website. The situation is that on of the website, user files up a form and it is submitted. On submission, the page should...
3
by: Tarik Monem | last post by:
Hi Everyone, Still a newbie with FLEX, and I've passed arrays using AJAX to FLEX before, but I've never passed links to FLEX. Basically, this is the OUTPUT, which I wanted, but I'm given an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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,...

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.