in pascal a do it so:
Code: Select all
var k:integer;
begin
while not eoln do
begin
read(k);
.
.
.
end;
end.
Moderator: Board moderators
Code: Select all
var k:integer;
begin
while not eoln do
begin
read(k);
.
.
.
end;
end.
Code: Select all
int k; char c;
while (scanf("%d%c", &k, &c) == 2 && c != '\n') { ... }
thank youmf wrote:You can do it with this code:(Of course, this assumes that there are no trailing spaces at the end of line.)Code: Select all
int k; char c; while (scanf("%d%c", &k, &c) == 2 && c != '\n') { ... }
Code: Select all
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string line;
getline(cin, line);
stringstream stream(line);
int k;
while (stream >> k)
{
cout << k << endl;
}
return 0;
}