Rayan Alkhelaiwi Rayan Alkhelaiwi - 1 year ago 106
C++ Question

How to convert this segment of Java code to C++?

I have a difficulty to convert the following Java code into a C++ code:

java.io.File input = new java.io.File("CScourses.txt");
java.util.Scanner keyboard = new java.util.Scanner(input);

while (keyboard.hasNext()) {

courseNumM = keyboard.next();

courseNumM is a string.

Answer Source

The simplest translation would be to use std::ifstream, eg:

#include <fstream>

std::ifstream input("CScourses.txt");
std::string courseNumM;

while (input >> courseNumM) {
    // use courseNumM as needed...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download