#include <iostream>
using namespace std;
int main(){
int x;
cout << "Hello world"" endl;
cin >> x;
return 0;
}
Helpful when inputs are line oriented, i.e., user will enter a line and a program has to check if inputs on that line are correct. Can be used to extract inputs in the line
#include <sstream>
#include <string>
int main(){
int ID;
string name;
string inputline = "1001 Joe";
stringstream myStringStream(inputLine); //create a string stream initialized with inputLine
stringstream >> ID; //input into ID
myStringsStream >> name; //input into name
cout << "Name: " << name << endl << "ID: " << ID << endl;
myStringStream << name << ID;
cout << myStringStream.str(); //converts a string stream to a string to print it
return 0;
}
getline(cin, inputLine);
will grab an entire line entered by user#include <fstream>
using namespace std;
int main(){
ofstream outfile("myFile.txt");
string name = "We are engineers!";
outfile << name;
outfile.close();
}
ofstream outfile ("myfile.txt", ios::app);
#include <fstream>
using namespace std;
int main(){
ifstream inputfile("myfile.txt");
int num1, num2, num3;
inputfile >> num1 >> num2 >> num3; //input from file
inputfile.close();
return 0;
}
inputfile.open("/u/prof/emarasal/ece244/lab1/myfile.txt");
inputfile.open("lab1/myfile.txt");
inputfile.open("../myfile.txt");
inputfile.open("myfile.txt");
outputfile.flush();
or outputfile < endl