Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to automatically combine variables 1 and 2, 3 and 4, 5 and 6, and so on automatically so I can print them to the screen simular to
cout << 1 <<" "<< 2 << endl;
But instead it would simply be
cout << 1 << endl;

What I have tried:

#include <iostream>
#include <vector>
#include <fstream>
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(1) << '\n';
    in.close();

    return 0;
}
Posted
Updated 1-May-18 7:19am
Comments
Richard MacCutchan 1-May-18 4:15am    
Where are the variables in question, what do they contain, and how are you trying to combine them?

1 solution

should be very easy
C++
int main( void )
{
    std::string text;
    std::string word;
    std::vector<std::string> file;

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

    while ( in >> word ) {
        //file.push_back( word );
        text += word;
    }
    // easy print out of the full text
    cout << text << endl;
 
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