D
Developwebsites
I want to enter sentences with blanks between words,
names, cities, new york, pam anderson, etc.
as in:
Input"enter your name";name$
print"your name is: ";name$
C++ seems to make it rather difficult to do a simple thing as that.
#include<string>
using namespace std;
struct Cities {
string city;
int temp;
};
Cities info;
cout<<"\nplease enter "<<info[t].city<<"'s temp: ";cin>>info[t].temp;
if user enters 'new york' program crashes. why cant there be
a space when entering a string?
it works with cin.get(), but in a while loop the input is blank
after first name is entered.
this works:
#include <iostream.h>
void main( void ) {
char ch;
cout << "Enter a string:" << endl;
while( ( ch = cin.get() ) != '\n' ) {
cout<<ch;
}
cout << endl;
}
but how do i use it in a array, class or a struct?
names, cities, new york, pam anderson, etc.
as in:
Input"enter your name";name$
print"your name is: ";name$
C++ seems to make it rather difficult to do a simple thing as that.
#include<string>
using namespace std;
struct Cities {
string city;
int temp;
};
Cities info;
cout<<"\nplease enter "<<info[t].city<<"'s temp: ";cin>>info[t].temp;
if user enters 'new york' program crashes. why cant there be
a space when entering a string?
it works with cin.get(), but in a while loop the input is blank
after first name is entered.
this works:
#include <iostream.h>
void main( void ) {
char ch;
cout << "Enter a string:" << endl;
while( ( ch = cin.get() ) != '\n' ) {
cout<<ch;
}
cout << endl;
}
but how do i use it in a array, class or a struct?