-
input from file
say you input from a file
"name1 1 2 3 4 5 6"
"name2 1 2 3 4 5 6"
"name3 1 2 3 4 5 6
"name4 1 2 3 4 5 6"
"name5 1 2 3 4 5 6"
"name6 1 2 3 4 5 6"
you want to store "name" as a string, and 1 2 3 4 5 6 as int.
what functions would you use?
and what would be the sentinel for the loop?
-
>>and 1 2 3 4 5 6 as int
As one int or as 6 different integers?
So the "name1" is gong to become just "name"?
You want to read about the String.split method and learn a few handy regexes.
-
then is still have to convert "1 2 3 4 5 6" into int?
whats the equivalent of putback(), getline(), and get() in java?
-
I don't know what the methods you are asking do so I can't say.
You can read the file using FileReader/BufferedReader combination and then read it line by line using the BufferedReader.readLine() method. To convert from String to int just use Integer.parseInt. Read about all those things in the API specs and in Sun's Java tutorial.
-
thats c++.but is there anyway that i can read it without having to convert it?
-
You can read each whole line into a String, then use Scanner.next() to get the name and Scanner.nextInt() to get each integer.