Computing.Net > Forums > Programming > stupid string?!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

stupid string?!

Reply to Message Icon

Name: Deimos
Date: December 9, 2007 at 09:37:55 Pacific
OS: Windows Xp professional S
CPU/Ram: CPU:2.6x2Ghz Ram:2048mbs
Product: Deimos's nr1
Comment:

Hello,

One of the exercises in my 4th chapter(vectores and iterators) is to make a "progam that allows the user to maintain a list of his/hers favourite game titles, add a game title and delete a game title using vectores and iterators" I know i have to create a vector that uses strings and so I did here:

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>//this one's for sorting.

using namespace std;

int main(){
int gn = 3, i = 0;

vector<string> games(gn);
vector<string>::iterator iter;
string f, f1, f2;
cout << "Your list's capacity is of " << games.capacity() << " games.\n";
cout << "Type your favourite game: ";
cin >> f;
cout << "Type your 2nd favourite game: ";
cin >> f1;
cout << "Type your third favourite game: ";
cin >> f2;

games.push_back(f);
games.push_back(f1);
games.push_back(f2);

cout << "This is your current game list: ";
for(iter = games.begin(); iter != games.end(); ++iter){
++i;
cout << i << " - " << *iter << endl;
}
system("Pause");
}

But the stupid string is space delimited...is there anyway i can solve this? I think my book's preety stupid for not telling me how to do this...

Best Regards ;)

PS: Razor2.3 I know you said that i should stop posting here...but im familiar with this forum xD Can you send your email adress to mine so that you can help me out more easily? (I think you just have to click my name)

AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: December 9, 2007 at 20:29:40 Pacific
Reply:

Deimos: Razor2.3 I know you said that i should stop posting here
I said no such thing. I DID say this forum is too general for you to gain C++ knowledge by lurking, but that doesn't prevent you from asking.

Deimos: But the stupid string is space delimited...is there anyway i can solve this?

getline(cin, f);


0

Response Number 2
Name: Deimos
Date: December 10, 2007 at 00:27:12 Pacific
Reply:

Ok its working thanks :D

Best Regards

AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


javascript hangman game h... random string with batch



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: stupid string?!

Strings, finding and storing words www.computing.net/answers/programming/strings-finding-and-storing-words/8423.html

Two dimensional array of strings www.computing.net/answers/programming/two-dimensional-array-of-strings/681.html

C++ String Project? www.computing.net/answers/programming/c-string-project/13463.html