Browse over 20 million
homework answers & study documents

Computer Science

C++ Visual Studio 2013 Binary File IO

Type

Lab

Rating

Showing Page:
1/3
// CPPFileIO.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <ctype.h>
using namespace std;
bool isNumber(string word)
{
for (auto it = word.cbegin(); it != word.cend(); ++it)
{
if (!isdigit(*it))
return false;
}
return true;
}
bool isAlphabet(string word)
{
for (auto it = word.cbegin(); it != word.cend(); ++it)
{
if (!isalpha(*it))
return false;
}
return true;
}
void readMixed()
{
string buf;
int theValue;
vector<int> numbers;
vector<string> alphas;
vector<string> tokens; // Create vector to hold our words
std::ifstream in("mixed.bin");
if (in.is_open())
{
std::stringstream buffer;
buffer << in.rdbuf();
while (!buffer.eof())
{
while (buffer >> buf)
tokens.push_back(buf);
}
for (unsigned i = 0; i < tokens.size(); i++)
{
if (isNumber(tokens.at(i)))
numbers.push_back(atoi(tokens.at(i).c_str()));
else if (isAlphabet(tokens.at(i)))
alphas.push_back(tokens.at(i));
}

Sign up to view the full document!

lock_open Sign Up

Sign up to view the full document!

lock_open Sign Up

Sign up to view the full document!

lock_open Sign Up

Anonymous
Outstanding. Studypool always delivers quality work.

Anonymous
Thanks for the help.

Anonymous
<3 it, thanks for saving me time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4