Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,396 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,108 people online right now. Registration is fast and FREE... Join Now!




Taking spaces out of multi-word strings

 
Reply to this topicStart new topic

Taking spaces out of multi-word strings

megan09
29 Oct, 2006 - 05:49 PM
Post #1

New D.I.C Head
*

Joined: 18 Oct, 2006
Posts: 2


My Contributions
[I'm trying to create a function which removes the spaces from a multi-word input string. When I ran my program I got the following errors: "warning C4018: '<=' : signed/unsigned mismatch" and "error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Ax> &' from 'overloaded-function'". What am I doing wrong?? Here's my code]



#include <iostream>
using namespace std;
#include <string>
#include <sstream>

int main ()
{
string s;
cout << "Enter a string: " << endl;
getline (cin, s);
string remove_spaces();

int i=1;
while (i<=s.length());
{
string t(s.substr(i,s.find(" ")));
remove_spaces = remove_spaces + t;

{
cout << remove_spaces << endl;


return 0;



}
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Taking Spaces Out Of Multi-word Strings
29 Oct, 2006 - 05:52 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
string remove_spaces();
What is this supposed to represent? Is it a string declaration? A call to a function? A function prototype? After that declaration, you are then streating it like a string...trying to append to it.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:55AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month