Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ txt文件中的数据赢得';用户输入[C+;+;] 字符串行; 流媒体搜索; 短回路=0; 常数int SIZE=6; 线重[尺寸]; int索引[6]={1,2,3,4,5}; int i; 智力选择; 字符串权重变化; searc_C++_Loops_Input_Output_Text Files - Fatal编程技术网

C++ txt文件中的数据赢得';用户输入[C+;+;] 字符串行; 流媒体搜索; 短回路=0; 常数int SIZE=6; 线重[尺寸]; int索引[6]={1,2,3,4,5}; int i; 智力选择; 字符串权重变化; searc

C++ txt文件中的数据赢得';用户输入[C+;+;] 字符串行; 流媒体搜索; 短回路=0; 常数int SIZE=6; 线重[尺寸]; int索引[6]={1,2,3,4,5}; int i; 智力选择; 字符串权重变化; searc,c++,loops,input,output,text-files,C++,Loops,Input,Output,Text Files,txt文件中的数据赢得';用户输入[C+;+;] 字符串行; 流媒体搜索; 短回路=0; 常数int SIZE=6; 线重[尺寸]; int索引[6]={1,2,3,4,5}; int i; 智力选择; 字符串权重变化; search.open(“name.txt”)//打开存储用户详细信息的文本文件 if(search.is_open()) { 也许我错了,但它不应该是weight[1]=weightChange,而不是相反吗?如果我理解正确,您正试图从用户处读取数据并

txt文件中的数据赢得';用户输入[C+;+;]
字符串行;
流媒体搜索;
短回路=0;
常数int SIZE=6;
线重[尺寸];
int索引[6]={1,2,3,4,5};
int i;
智力选择;
字符串权重变化;
search.open(“name.txt”)//打开存储用户详细信息的文本文件
if(search.is_open())
{

也许我错了,但它不应该是
weight[1]=weightChange
,而不是相反吗?如果我理解正确,您正试图从用户处读取数据并写入文件,对吗?要做到这一点,您需要写入文件(运算符),可能您必须将>>运算符更改为weight[1];)应该是(搜索提示:这不会写入文件。提示:创建一个函数加载文件并返回数据,另一个函数获取数据并重新写入文件。
string line;
fstream search;
short loop = 0;
const int SIZE = 6;
string weight[SIZE];
int index[6] = { 1, 2, 3, 4, 5 };
int i;
int choice;
string weightChange;

search.open("name.txt"); //Opens the text file in which the user details are stored
if (search.is_open())
{
    cout << endl;
    while (getline(search, line)) { //While the program searches for the lines in the text file
        if (line.find("Current Weight(KG): ") != string::npos) { //If the string "Name" isnt the last word on the line
            weight[loop] = line; //Assings the strings read from the text file to the array called weight
            cout << index[loop] << ". " << weight[loop] << endl; //Outputs the index array which loops through the numbers in the array and outputs the weight variable which loops through the strings in the array
            loop++; //Iterates the loop 
        }
    }
        cout << "Which index would you like to change?" << endl;
        cout << "1, 2, 3, 4 or 5" << endl;
        cin >> choice;
        cout << "Weight being changed is " << weight[choice - 1] << endl;

        switch (choice) //Uses switch to allow the user to enter a number from the menu and then performs that function based on the user's input
        {
        case 1: //If the user enters choice 1, then the first weight index will be changed
            cout << "What would you like to change the user's weight to?" << endl;
            cin >> weightChange;
            weightChange = weight[1];

            search >> weight[1];

            cout << endl;
            break;
        }
}