in C you can do this
scanf("%fx + %fy", &x, &y);
and on the input you type
2x + 3y and x and y become 2,3 respectively.
I tried this in C++
cin >> x >> "x + " >> y >>"y";
why won't it work the same?
kwigibo
in C you can do this
scanf("%fx + %fy", &x, &y);
and on the input you type
2x + 3y and x and y become 2,3 respectively.
I tried this in C++
cin >> x >> "x + " >> y >>"y";
why won't it work the same?
kwigibo
EDIT........Sorry I had something here but I realized that this is not what you want, I just don't get your question.....but then again I also suck.
Last edited by incognito; 05-21-2002 at 07:58 PM.
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
Sorry I might be kind of slow, but I read your post like 5 times and still don't get your point.
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
Point taken, it is worded badly.
In C I can use scanf to skip over "expected input" such as the x+..y part. I tried a similar method in C++, which I thought would have the same effect. But it didn't how do I do it.
run the code below, and it'll show what I mean. use input such as
2x + 3y
76x + 9y
1x + 1y
etc
respectively you should get the outputs
2,3
76,9
1,1
Code:#include <stdio.h> int main() { int x,y; scanf("%dx + %dy", &x,&y); printf("\n\n%d\n%d\n",x,y); return 0; }
just use scanf. or if mixing input streams bothers you, read in a string and use a flavor of scanf to parse it.
Any suggestions on "a flavor of scanf"? and perhaps a small/simple example of its use which I could plugin to a file and run
Here's a flavor.
There's probably a way to do this using the strstream class from the Standard C++ Library. However I don't use strstream enough to know how.Code:#include <stdio.h> #include <iostream> using namespace std; int main() { char line[80]; int x,y; cin.getline(line,80); sscanf(line,"%dx + %dy", &x,&y); printf("\n\n%d\n%d\n",x,y); return 0; }