So where is the remaining code...?
Post it to get more help.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
> makewords( int a, int b, int c);
How does this match your description of a function taking 3 strings?
Read up on the string class.
There is plenty of functionality to say
- find a space in a string
- return sub-strings of a string.
- get the length of a string.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
string [50] makes no more sense than int[50]. Given you have included the string header file you supposedly will be using STL strings, which is fine. Under that scenario you could declare a single string like this:
string s;
or an array of strings like this:
string s[50];
but
string[50] doesn't cut the mustard.
To read a string that contains white space into an STL string use the following syntax:
getline(streamYouAreUsing, stringToStoreInputIn, terminatingChar);
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Little confused here, the std::string does more or less what you're asking.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
To me, the phrase "read in" means accept input from some stream; keyboard input , file input, whatever, not hard code with static string.
makewords() shouldn't take three ints, it should take three strings.
In your programs, if you make a mistake once, you may well make it again, as in your use of string[50. You need to correct each instance of the error, not just one.
Don't have two variables by the same name in any given program. That is don't have a string called a and an int called a.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
You're still using the string[50] syntax. If you don't stop it soon I'll have to assume you are doing it on purpose to irritate me.
This,
string("Computer Science");
is essentially the same problem. All variables need to be declared with a type and a name. If you don't give variables a name it's an error, period.
Likewise, this instruction:
"call a function makewords() which receives three parameters: a string which holds the original phrase and two strings to hold the two words"
requires that makewords() is passed three strings. You just pass the string. You don't need to worry about the length of the strings when passing them.
You should also be aware that functions need to be declared, though not necessarily defined before they are called. If you define a function before main, then you don't need a formal declaration. So, it's either:
#include <iostream>
#include <string>
using namesspace std;
//formal declaration of foo before main(), define foo after main()
void foo(string);
int main()
{
//declare a string with the name string1
string string1 = "Hello";
//call the function passing it a string
foo(string1);
}
//define the function called foo
void foo(string x)
{
cout << x;
}
OR
#include <iostream>
#include <string>
using namesspace std;
//define the function called foo before main(), no formal declaration needed
void foo(string x)
{
cout << x;
}
int main()
{
//declare a string with the name string1
string string1 = "Hello";
//call the function passing it a string
foo(string1);
}
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396