C++ n00b here
To separate a string into two words you would have to find the length of the string you want to separate then find the space that separates them then separate them into two strings by using the .substr() method (well that is what I do)
for example:
#include <iostream>
using namespace std;
int main()
{
string name;
cout<<"enter two words: ";
getline(cin, name);
int length = name.length();
char space = name.find(" ");
string first = name.substr(0, space);
space = space + 1;
string last = name.substr(space, length);
cout<<"first: "<<first<<endl;
cout<<"second: "<<last;
int hold;
cin>>hold;
return 0;
}
output:
enter two words: two words
first: two
second: words
This is what I was taught:
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main ()
{
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
int random = rand();
cout<<random<<endl;
//you can change the range of the random number
random = rand()%10; //the max number this can generate is 10
cout<<random;
}