Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.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++;在文件中保存变量 我是C++新手,我想找到一种方法,使程序存储在变量中。我不明白如何保存文件或变量,以便在下次程序打开时能够重用。例如,假设我制作了一个请求用户名并将其保存在变量中的程序,我如何才能存储该变量,以便该程序能够在以后使用时实际获取该变量?_C++_Variables - Fatal编程技术网

C++;在文件中保存变量 我是C++新手,我想找到一种方法,使程序存储在变量中。我不明白如何保存文件或变量,以便在下次程序打开时能够重用。例如,假设我制作了一个请求用户名并将其保存在变量中的程序,我如何才能存储该变量,以便该程序能够在以后使用时实际获取该变量?

C++;在文件中保存变量 我是C++新手,我想找到一种方法,使程序存储在变量中。我不明白如何保存文件或变量,以便在下次程序打开时能够重用。例如,假设我制作了一个请求用户名并将其保存在变量中的程序,我如何才能存储该变量,以便该程序能够在以后使用时实际获取该变量?,c++,variables,C++,Variables,您只需将该变量保存在一个文件中,并在下次运行程序时从该文件中读取即可 比如说,你有变量inta将值分配给a=10。可以使用以下代码将该变量保存在文本文件中: ofstream file; file.open ("filePath.txt"); file << a; file.close(); 流文件的; file.open(“filePath.txt”); 文件您想保存变量名还是只保存变量的内容?保存为二进制还是文本? ofstream output_fil

您只需将该变量保存在一个文件中,并在下次运行程序时从该文件中读取即可

比如说,你有变量
inta将值分配给
a=10
。可以使用以下代码将该变量保存在文本文件中:

  ofstream file;
  file.open ("filePath.txt");
  file << a;
  file.close();
流文件的
;
file.open(“filePath.txt”);

文件您想保存变量名还是只保存变量的内容?保存为二进制还是文本?
    ofstream output_file( filePath );
    ostream_iterator<int> output_iterator( output_file, "\n" );
    // Passing all the variables inside the vector from the beginning of the vector to the end.
    copy( b.begin( ), b.end( ), output_iterator );
std::vector<double> newVector;
ifstream input_file( filePath.txt );
double tempVar;
while ( input_file >> tempVar )
{
    newVector.push_back( tempVar );
}