程序正在努力打开文件

问题描述 投票:0回答:1

我目前正在将Clion用于一个学校项目,该项目涉及为MIPS创建汇编器。我一直在尝试对其进行测试,但是我的ifstream.open()无法找到与程序位于同一文件夹中的文本文件。我使用与以前项目中相同的代码来打开文件,实际上是复制粘贴内容,无论出于何种原因它都无法正常工作。我不需要程序中其他任何问题的帮助,我可以自行修复这些错误,但是我认为该文件业务与clion造成的痛苦有关,这使我想拔头发。

我已经尝试将我的istream声明为istream和ifstream,并输入文件名以及从C:到文件的整个文件路径。

#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
#include <array>


using namespace std;


//void GrowArrays(int &size, int *intArray, string *stringArray);
bool RegisterCheck(string &binary, string hold);


int main() {
    string fileName;
    string binaryOut;
    string outFileName;

    string tempString;
    string holdString;
    int holdInt;
    int binaryHold[16];

    int arraySize = 0;
    string labels[arraySize] = {};
    int labelAddress[arraySize] = {};
    string stringTemp[arraySize];
    int tempInt[arraySize];
    int binaryCounter;
    int instructionCounter = 0;

    ifstream fin;
    ifstream fint;


    cout << "Please input the name of the file you wish to open";
    cin >> fileName;
    cout << "please input the name of the file you wish to write to.";


    fin.clear();
    fint.clear();
    fin.open(fileName);
    fint.open(fileName);
    while(!fin) {
        cout << "File not opened, try again.";
        cin >> fileName;
        fin.open(fileName);
        fint.open(fileName);
    }     
`    `//not making it to rest of program after this

应该打开文件并继续在程序中,但是由于无法打开文件而陷入循环中

c++ iostream clion
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.