Archived

This topic is now archived and is closed to further replies.

RanBlade

Anohter method besides gets(); to get mutlipe word string.

Recommended Posts

I have googled and checked MSDN for the last hour and cant find anyhting(i dont think I have the rigth wording). Anyway gets(); acts werid but cin >> dosent allow more then one word per string... does anyone know any other IO functions that allow you to submit a multi word string?.. Thx

RanBlade "Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...Passion is where great games come from, if you dont live and breathe games you shouldn''t be in the games industry." - Dave Pottinger, Ensemble Studios
[GameDev][C++ Page][Game Tutorials][FreeBSD][HawkNL(Hawk Network Library)][NeHe Productions][Mage Tower Ent-My Site]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you should look into std::getline or cin.getline. std::getline is found in the iostream header

std::getline works with the string class(header string).
cin.getline works with char arrays.

here are some sample programs

#include <iostream>
using namespace std;

int main() {
const int MAX_LETTERS = 15;
char name[MAX_LETTERS];

cout << "Enter your name: ";
cin.getline(name, MAX_LETTERS);
cout << "You entered: " << name << endl;

return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main(void) {
std::string name;
cout << "Enter your name: ";
getline(cin, name);
cout << "You entered: " << name << endl;

return 0;
}

Share this post


Link to post
Share on other sites
Thx a lot... those work great



RanBlade
"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...Passion is where great games come from, if you dont live and breathe games you shouldn''t be in the games industry." - Dave Pottinger, Ensemble Studios

[GameDev][C++ Page][Game Tutorials][FreeBSD][HawkNL(Hawk Network Library)][NeHe Productions][Mage Tower Ent-My Site]

Share this post


Link to post
Share on other sites