C++ It keeps telling me build fail when i run it. Please help me find the mistakes. ..... #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const string SPACE = " "; const int NUM_STRINGS = 3; int main () { int randomNum; string baseStr; string searchStr; int foundWordPos; int endWordPos; string wordStr; string phrase[NUM_STRINGS]; phrase[0] = "peter piper picked a peck of pickled peppers"; phrase[1] = "how much wood would a woodchuck chuck if a woodchuck could chuck wood"; phrase[2] = "the big bug bit the little beetle, but the little beetle bit the big bug back"; string search[NUM_STRINGS]; search[0] = "pi"; search[1] = "wo"; search[2] = "bi"; srand(time(NULL)); randomNum = (rand() % NUM_STRINGS); cout << "randomNum:" << randomNum << endl; baseStr = phrase[randomNum]; cout << "baseStr:" << baseStr << endl; searchStr = search[randomNum]; cout << "searchStr:" << searchStr << endl; cout << endl; foundWordPos = baseStr.find(searchStr); string. while (foundWordPos != string::npos) { endWordPos = baseStr.find(SPACE, foundWordPos); to foundWordPos) wordStr = baseStr.substr(foundWordPos, endWordPos - foundWordPos); cout << wordStr << " "; foundWordPos = baseStr.find(searchStr, endWordPos); } }
C++
It keeps telling me build fail when i run it. Please help me find the mistakes.
.....
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const string SPACE = " ";
const int NUM_STRINGS = 3;
int main () {
int randomNum;
string baseStr;
string searchStr;
int foundWordPos;
int endWordPos;
string wordStr;
string phrase[NUM_STRINGS];
phrase[0] = "peter piper picked a peck of pickled peppers";
phrase[1] = "how much wood would a woodchuck chuck if a woodchuck could chuck
wood";
phrase[2] = "the big bug bit the little beetle, but the little beetle bit the
big bug back";
string search[NUM_STRINGS];
search[0] = "pi";
search[1] = "wo";
search[2] = "bi";
srand(time(NULL));
randomNum = (rand() % NUM_STRINGS);
cout << "randomNum:" << randomNum << endl;
baseStr = phrase[randomNum];
cout << "baseStr:" << baseStr << endl;
searchStr = search[randomNum];
cout << "searchStr:" << searchStr << endl;
cout << endl;
foundWordPos = baseStr.find(searchStr);
string.
while (foundWordPos != string::npos) {
endWordPos = baseStr.find(SPACE, foundWordPos);
to
foundWordPos)
wordStr = baseStr.substr(foundWordPos, endWordPos - foundWordPos);
cout << wordStr << " ";
foundWordPos = baseStr.find(searchStr, endWordPos);
}
}

Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images









