如何一次合并两个变量。 [英] How do I combine variables two at a time.

查看:113
本文介绍了如何一次合并两个变量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动组合变量1和2,3和4,5和6,依此类推,这样我就可以将它们打印到屏幕上,类似于

cout<< 1<<<<"<< 2<< endl;

但它只是简单地说是

cout<< 1<<结束;



我的尝试:



 #include< iostream> 
#include< vector>
#include< fstream>
int main(void)
{
std :: string word;
std :: vector< std :: string>文件;

std :: ifstream in(Files.txt);

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

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

std :: cout<< file.at(1)<< \\\
;
in.close();

返回0;
}

解决方案

应该非常简单

  int  main( void 
{
std :: string text;
std :: string word;
std :: vector< std :: string>文件;

std :: ifstream in Files.txt);

while in >> word){
// file.push_back(word);
text + = word;
}
// 轻松打印全文
cout<<文字<< ENDL;


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;
}

解决方案

should be very easy

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;


这篇关于如何一次合并两个变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆