이것은 "더 나은"토론이 아닙니다.자바 라인 IO 대 C++ IO?
나는 C++ 프로그래머이며, Java 파일 IO를 수행하는 방법을 알지 못해서 매우 바보 같다고 느낍니다.
나중에 읽을 수 있도록 여러 데이터 유형을 파일에 저장해야합니다. 여기에는 정수와 가변 길이의 문자열이 포함됩니다. C++에서
은, 난 그냥 사용할 수 있습니다
//wont actually know the value of this
string mystr("randomvalue");
//the answer to the Ultimate Question of Life, the Universe, and Everything
int some_integer = 42;
//output stream
ofstream myout("foo.txt");
//write the values
myout << mystr << endl;
myout << some_integer << endl;
//read back
string read_string;
int read_integer;
//input stream
ifstream myin("foo.txt");
//read back values
//how to do accomplish something like this in Java?
myin >> read_string;
myin >> read_integer;
감사합니다 아주 많이!
++'문자열) (read_string,'brackats를 제거하거나 문자열 전에'class' 키워드를 추가해야합니다 문자열이 아니라 string.You의 해상력을 반환하는 함수의 선언입니다. – UmmaGumma
[스캐너] (http://download.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html)는'>>'과 유사한 것들을 도울 수 있습니다. 각 라인을 읽고 수동으로 변환하는 것이 덜 고통 스럽습니다. –
'string read_string();'이 명백하게 생각하는 것을 수행하지 않으므로 C++ 예제가 손상되었습니다. 또한 "randomvalue"대신에 "random value"를 사용하면 어떻게 될지 알고 있습니까? – 6502