Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Every other output in this for loop is a series of digits. I would like to check if the output is digits and if they are. Print them to the console screen.

What I have tried:

#include<iostream> //i.o
#include<cctype> //for isdigit
#include<sstream> //to phrase string
#include<string>
#include <vector>
#include <fstream>

using namespace std;
int main( void )
{
    std::string word;
    std::vector<std::string> file;

    std::ifstream in( "Files.txt" );

    while ( in >> word )
        file.push_back( word );

    for ( size_t i=0; i<file.size(); i++ )

        std::cout<< file.at(i) << '\n';
    in.close();

    return 0;
}
Posted
Updated 4-May-18 22:34pm

1 solution

You need to get the content of the string and compare each character to see if it is a digit. You could use the C library function isdigit, iswdigit, _isdigit_l, _iswdigit_l[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900