There are a couple of issues here so I'll do my best to sort them out. First, in c++ programs, it's strongly advised to not use "C strings". These are the strings you're referring to by declaring str1[100] as a char type. You should instead use a std::string, like this:
#include <iostream>
#include <string>
int main()
{
std::string str1 = "Sun Moon Earth";
std::string str2;
std::string str3;
std::string str4;
size_t foundSpacePosition = str1.find(" "); //std::string::find() returns the position of the first found instance of the string you're passing it, which is in this case the space.
str2 = str1.substr(0, foundSpacePosition); //std::string::substr returns a substring from the first argument to the second argument.
//In this case, we want a substring from the 0th position to the found position of the space.
std::string tempString = str1.substr(foundSpacePosition+1); //If you only pass one argument to substr(), it will return a substring from that position to the end of the string
//Because std::string::find() only finds the first instance of the character, we must remove it to continue.
//We will make a copy of this so as to not modify the original str1, saving it into tempString
foundSpacePosition = tempString.find(" "); //Find the next space
str3 = tempString.substr(0, foundSpacePosition); //Same as before
tempString = tempString.substr(foundSpacePosition+1); //Same as before
foundSpacePosition = tempString.find(" "); //Same as before
str4 = tempString.substr(0); //Since there is nothing else left in this string,
//we can just go from the 0th position to the end
std::cout << "str1 = " << str1 << std::endl;
std::cout << "str2 = " << str2 << std::endl;
std::cout << "str3 = " << str3 << std::endl;
std::cout << "str4 = " << str4 << std::endl;
return 0;
}
And the output:
1 2 3 4
str1 = Sun Moon Earth
str2 = Sun
str3 = Moon
str4 = Earth