-
guys, i got my coding done, i end up using getline , and parse the string... I knew this methdo all along, but I was trying to ask if it is possible to read from cin to integer while able to detect line by line, n somebody ans me no! -Thx
------------------
DHAHL3seasons GP:73 G:121 A:55 Pts:176 GWG:12 +/-:184
UWSWA1season GP:9 G:12 A:8 Pts:20 GWG:3 +/-:-3
MCBHL1season GP:4 G:5 A:5 Pts:10 GWG:0 +/-:9
uwcdc.com or namgor.com
-
It may be possible using some sort of getc/ungetc thing, but those are C functions.
-
Using scanf():
int myint ;
char temp ;
while(true)
{
scanf("%d%c",&myint,&temp) ;
if (temp=='\n')
break ;
else sum+=myint ;
}
Using cin :
//cin ignores whitespace(s),tabe(s),newline. this goes to input buffer. catch them //with getchar() or something else and then compare
int myint ;
while(true)
{
cin >> myint ;
if (getchar()=='\n')
break ;
else sum+=myint ;
}
HOPE THAT ANSWERS.
-
//edit sum+=myint should come before newline check
Using scanf():
int myint ;
char temp ;
while(true)
{
scanf("%d%c",&myint,&temp) ;
sum+=myint ;
if (temp=='\n')
break ;
}
Using cin :
//cin ignores whitespace(s),tabe(s),newline. this goes to input buffer. catch them //with getchar() or something else and then compare
int myint ;
while(true)
{
cin >> myint ;
sum+=myint ;
if (getchar()=='\n')
break ;
}
HOPE THAT ANSWERS.
-
-
Couldn't you just use getline then cin.ignore(), cin.ignore(80, '\n') (depeding on the compiler) to get to the next line?