Hello Group,
I have been meaning to have this opportunity to share my problems
with someone all this while. Thank God I have finally gotten a place to do
that. I hope I will be accommodated.
I am a computer science student and will want to develop my skills
in programming. I have done some like BASIC, PASCAL. I am about starting C. I
have actually gotten ANSI C by Ritchie as recommended by the moderator of this
group. I wish to therefore plead that if there is any other thing required of
me to successfully do this course well please don�t hesistate to pass it
across to me. Because at the moment my school syllabus reflects JAVA. But
because I am not done yet with C I can�t venture into it yet. So please I need
your supports now because I have just got 2 more years to round up.
Thanks
Oche (Nigeria).
"Victor A. Wagner Jr." <[EMAIL PROTECTED]> wrote:At Thursday 2004-12-02 15:47,
you wrote:
>Here you go:
>
> #include <string>
> #include <iostream>
> #include <stack>
>
> int main(void)
> {
> std::string s;
> std::cout << "Enter the sentence: " << std::flush;
> std::stack<std::string> ss;
> do
> {
> std::cin >> s;
> ss.push(s);
> } while (std::cin.peek() != '\n');
>
> while (!ss.empty())
> {
> std::cout << ss.top() << ' ';
> ss.pop();
> }
> std::cout << std::endl;
> }
if you dislike writing lots of loops, here's one that heavily uses the
library (it also allows you to input more than one sentence)
I've commented it rather heavily since many aren't familiar with the
standard C++ library
// string and getline(istream&, string)
#include <string>
// cin and cout
#include <iostream>
// istringstream
#include <sstream>
// vector
#include <vector>
// istream_iterator and ostream_iterator
#include <iterator>
// copy
#include <algorithm>
using namespace std;
int main()
{
string line; ///<someplace for the input
/// loop while we're getting good data (the \n at the beginning
/// means we won't have to output one later)
/// I've split the conditions of the while into 3 lines to make them
easier to track
/// the expression (cout << blah) returns cout (which tests true if
the stream is still good)
/// we then get an entire line into the variable line (getline also
returns the stream)
/// finally we test to see if we've input anything or just got an
empty line
while ((cout << "\nEnter the sentence(just enter to exit): ")
&& getline(cin, line)
&& line.size()
)
{
/// construct an istringstream from the line we just read
/// remember that the operator >> when reading a string stops on
whitespace
/// that is, it will read one word at a time.
istringstream ist(line);
/// what follows is called a range constructor (every STL
container has one)
/// we create the vector using beginning and ending iterators.
/// the extra parens around the 1st argument to the constructor
are required
/// (see "Effective STL" Item 6)
///
vector<string> the_words((istream_iterator<string>(ist)),
istream_iterator<string>());
/// now just copy them out (backwards) to the output (separate
them by one space)
/// use reverse limits rbegin() and rend() to do that
copy(the_words.rbegin(), the_words.rend(),
ostream_iterator<string>(cout, " "));
}
}
[deleted]
Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
"There oughta be a law"
>-----------------------------------------~-~>
CHECK THE ARCHIVE BEFORE POSTING!!!! Archive is available at
http://www.eScribe.com/software/C-Paradise/
>------------------------------------------_->
Yahoo! Groups SponsorADVERTISEMENT
---------------------------------
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/C-Paradise/
To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~->
>-----------------------------------------~-~>
CHECK THE ARCHIVE BEFORE POSTING!!!! Archive is available at
http://www.eScribe.com/software/C-Paradise/
>------------------------------------------_->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/C-Paradise/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/