从文件中读取一行字符串 [英] Read a line of strings from a file

查看:51
本文介绍了从文件中读取一行字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从文件中读取一整行字符串,以便执行某些操作.使用下面的代码,密文"为空.

i want to read a full line of strings from a file in order to do some operations. With the bellow code the "Ciphertext" is empty.

我的代码:

#include<iostream>
#include<string.h>
#include<stdlib.h>
#include <string>
#include <fstream>
using namespace std;

int main(int argc, char **argv)
{
    ifstream myfile("C:\\encr_affine.txt");
    string Ciphertext;

    while (!myfile.eof())
    {
        getline(myfile, Ciphertext);
    }

    //some code here

myfile.close();

}

推荐答案

读取文件中的一行字符串的答案是:

The answer for reading a line of strings in a file was :

while (getline(myfile, Ciphertext))
{
            //reading the ciphertext from the file
}

这篇关于从文件中读取一行字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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