Hello
This is an example program that came with my book, it demonstates the use of the varable string, but i changed it a little so that the user could writte his own phrase
~The code~
#include<iostream>
#include<string>
using namespace std;
int main(){
//define variables
string phrase;
string statement;
int pos;
//ask the user for a phrase
cout << "Enter a phrase: ";
cin >> phrase;
cout << "The phrase is " << phrase << endl;
//number of chars
cout << "The phrase's number of characters is " << phrase.size() << endl;
//ask the user for a position
cout << "Enter position:";
cin >> pos;
//Show the user what's the char in the chosen position
cout << "The charcter in position " << pos << " is " << phrase[pos] << endl;
//ask the user for an expression
cout << "Enter expression:";
cin >> statement;
//expression not found: inform the user of that
//expression found: say were the expression starts
if(phrase.find(statement) == string::npos){
cout << "No such statement found" << endl;
}else{
cout << "The statement " << statement << " begins at position " << phrase.find(statement) << endl;
}
system("Pause");
}
The thing is, when I enter a phrase with multiple words an WINDOWS error msg shows up saying:
"stringObj.exe found a problem and will be closed, we are sorry for any...etc etc"
Does the string object has some sort of limitation that stops the user from entering multiple words?? Or is there anything wrong with my compiler/my computer???
Best Regards
AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;