Posts

Showing posts from February, 2017

C++ Program: Counting letters,words,etc in input

#include <iostream>
#include <fstream>

int main()
{
std::string word;
std::getline(std::cin,word);
std::ofstream outf;
outf.open("lab3.txt");
outf<<word<<std::endl;
outf.close();
    std::ifstream lab3;

    lab3.open("lab3.txt");
    int countletters=0,countnum=0,countpunc=0,countspace=0,words=0,line=0;
    char character,prevchar = 0;
    if(!lab3)
    {
        std::cout << "Could not open file \n";
        return 1;
    }
    while(lab3.get(character) && !lab3.eof())
    {
        if(isalpha(character))
        {
            countletters++;
        }

C++ STL : Reading Elements from Vector until EOL

/* In this program we are entering elements in two vector. We can enter elements if we are pressing "space key".
 If we press "Enter" then we will start to enter in new vector
*/
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
using namespace std;
std::vector<int> read_vector()
{
    std::string line = "";
    std::getline(std::cin, line);
    std::istringstream iss(line);

    std::vector<int> v;

    int x = 0;
    while (iss >> x)
        v.push_back(x);

    return v;
}

int main()
{

Popular Posts

C++: Selection sort using STL

Top 10 Web Sites Every Programmer Should Visit Daily