Reverse Words

This is a discussion on Reverse Words within the C++ Programming forums, part of the General Programming Boards category; please I want to reverse word using stl like that input this is a test output test a is this...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Location
    Egypt
    Posts
    7

    Reverse Words

    please I want to reverse word using stl like that

    input

    this is a test

    output

    test a is this

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Show the code that you have so far.
    Kurt

  3. #3
    Registered User
    Join Date
    Aug 2012
    Location
    Egypt
    Posts
    7
    Code:
    #include<iostream>
    #include<string>
    #include<vector>
    using namespace std;
    int main()
    {
    	string str;
    	int x;
    	vector<string>v;
    	cin>>x;
    	cin.ignore();
    	for(int i=1;i<=x;i++)
    	{
    		getline(cin,str);
    		str.rbegin()==str.rend(); 
    		cout<<"Case #"<<i<<": "<<str<<endl;
    	}
    	return 0;
    }
    but it didnt work :/

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    Line 15 does not do anything.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Aug 2012
    Location
    Egypt
    Posts
    7
    how could i reverse a vector with string????

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,206
    Quote Originally Posted by sarasaad View Post
    how could i reverse a vector with string????
    Given that your code shows absolutely no attempt to reverse anything, how about you think a bit more?

    This is not a free code factory and it is not a free homework factory, and you will not get help here unless you demonstrate effort to solve the problem (i.e. post something that people can look at and realise you have genuinely tried).

    At this stage, your code reads strings, but neither inserts any of those strings into the vector, and also demonstrates no attempt to reverse anything. So you're not meeting your side of the deal.

    And hacking at random and bluffing will not work. The solution is VERY simple, so we know what people will probably do if they genuinely try.
    Last edited by grumpy; 08-04-2012 at 05:03 PM.
    Right 98% of the time, and don't care about the other 3%.

  7. #7
    Registered User
    Join Date
    Aug 2012
    Location
    Egypt
    Posts
    7
    I am really tried and I am already studied stl so I tried to solve this problem so I want to know how to reverse a string with vector and I search on the internet to find but it didn't work
    I'm sorry if I bothered you
    Last edited by sarasaad; 08-04-2012 at 05:14 PM.

  8. #8
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,635
    Your code does not actually use the vector that you declared. If you put each of the words in the vector, all you really have to do is figure out how to arrange the output in reverse.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,439
    Quote Originally Posted by sarasaad View Post
    I am really tried and I am already studied stl so I tried to solve this problem so I want to know how to reverse a string with vector and I search on the internet to find but it didn't work
    I'm sorry if I bothered you
    You should be able to figure it out yourself! How does one reverse a string? Begin with that. If you cannot figure it out, then use a flowchart to help you out with the logic.
    Do this, at least, before asking for help with implementing your solution.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reverse the words of a sentence.
    By Mr.Lnx in forum C Programming
    Replies: 9
    Last Post: 04-24-2012, 02:15 AM
  2. reverse words
    By ydan87 in forum C Programming
    Replies: 6
    Last Post: 01-16-2012, 03:35 PM
  3. Reverse words in string
    By perrrson in forum C Programming
    Replies: 3
    Last Post: 10-26-2010, 07:01 AM
  4. reverse words in a string
    By kenni81 in forum C Programming
    Replies: 14
    Last Post: 02-05-2003, 10:52 AM
  5. Reverse words
    By Dr. Bebop in forum C Programming
    Replies: 4
    Last Post: 09-09-2002, 09:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21