This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> /// std::cout; /// std::endl; | |
#include <vector> /// std::vector <t> | |
#include <list> /// std::list <t> | |
int main () | |
{ | |
std::list <int> il = {1, 3, 3, 4, 5}; | |
std::vector <int> v1 = {1, 2, 3, 22, 5}; | |
if (il.size() == v1.size()) { /// if the two containers are the same |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
struct person | |
{ | |
std::string name; | |
int votes = 0; | |
}; | |
int main () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
int main () | |
{ | |
std::vector <int> vec = {22, 33, 2, 1, 2, 5}; | |
int i = 2; | |
for (std::vector <int>::iterator it = vec.begin(); it != vec.end(); ++it) { | |
if (*it == i ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <list> | |
#include <deque> | |
int main () | |
{ | |
std::list <std::deque <int> > list_deq; | |
std::deque <int> temp_deq, temp_deq2; | |
int temp_int = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
class Records { /// interface | |
public: | |
std::string &vec_ret (unsigned); | |
const std::string &vec_ret (unsigned) const; | |
const Records &push (const std::string &) const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
int main () | |
{ | |
std::ostringstream print; | |
int num1 = 0; | |
std::cout << "enter a number: "; std::cin >> num1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
int main () | |
{ | |
std::fstream read("sample.txt.txt", std::ifstream::in); | |
std::string temp_bn, temp_model; | |
double temp_price = 0.0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> /// std::cout; std::cin; std::endl; std::cin::badbit; std::ostream; std::istream; std::getline; std::cin::setstate; | |
#include <fstream> /// std::ofstream; std::ifstream; std::ofstream::out; std::ofstream::app; | |
#include <string> /// std::string; | |
std::ostream &write(std::ostream &os, const std::string &file, const std::string &str) { /// writes a data in a file if overwrited then old data will erased | |
std::fstream file_m (file, std::ofstream::out); /// declares and define a filestream named file_m that has default mode of implicit std::ofstream::trunc and explicit std::ofstream::out | |
os << str << std::endl; /// writes the data in the file | |
return os; /// returns the stream state | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> /// std::cout; std::endl; | |
#include <fstream> /// std::ifstream; std::ofstream; | |
#include <vector> /// std::vector; | |
int main () | |
{ | |
std::vector <std::string> vec_data; /// declares and define vector name vec_data that stores strings | |
std::string temp_store; /// declares and define temp_store to store a temporary data | |
std::ifstream read("data.txt"); /// declares and define read that opens the file name data.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> /// std::istream; std::cout; std::endl; | |
std::istream &states (std::istream &is,const int &i) { | |
is >> const_cast<int&>(i); | |
if (is.rdstate () == std::cin.eofbit) | |
std::cout << "reached end of file " << std::endl; | |
else if (is.rdstate () == std::cin.badbit) | |
std::cout << "bad bit " << std::endl; | |
else if (is.rdstate () == std::cin.failbit) { |