【发布时间】:2018-04-21 18:53:05
【问题描述】:
我想从文件中读取一整行字符串以执行一些操作。使用下面的代码,“密文”为空。
我的代码:
#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();
}
【问题讨论】:
-
请删掉问题中所有无用的空行,因为它们会使这段代码无缘无故地滚动,并使其更难阅读。
-
@FeiXiang 谢谢 :) 如果你想把它写成答案...
-
我不确定这是您代码中的唯一问题。无论如何,此类调试问题通常都不会被很好地接受,因为您可能已经发现问题出在使用调试器的循环语句中,然后可能会查找并找到我链接到的帖子。 (虽然我没有投反对票)