当前位置: 首页>>代码示例>>C++>>正文


C++ ifstream::open方法代码示例

本文整理汇总了C++中ifstream::open方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::open方法的具体用法?C++ ifstream::open怎么用?C++ ifstream::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ifstream的用法示例。


在下文中一共展示了ifstream::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    fin.open("uppgift1.txt");
    fout.open("output3.txt");

    string word;
    int howMany=0;
    while(fin >> word >> ws)
    {
        cleanUp(word);
        words[word]++;
        howMany++;
    }
    int Unique = 0;

    for(map<string, int>::iterator it = words.begin(); it != words.end(); ++it)
         Unique++;



    fout << "Number of words in the file = " << howMany << endl;
    fout << "Number of unique words in the file = " << Unique << endl  << endl;
    fout << "Frequency table sorted alphabetically ..." << endl << endl;

    for(map<string, int>::iterator it = words.begin(); it != words.end(); ++it)
    {
        pair<int, string> p;
        p.first = it->second;
        p.second = it->first;

        toSort.push_back(p);
        fout <<left << setw (20) << it->first << setw (24) << it->second << endl;
    }



    sort(toSort.begin(), toSort.end());
    reverse(toSort.begin(), toSort.end());
    fout << endl << endl << "Frequency table sorted by frequence ..." << endl << endl;
  //  cout << "Frekventiell ordning: " << endl;
    for(vector< pair<int, string> >::iterator ite = toSort.begin(); ite != toSort.end(); ++ite)
    {
        fout << left << setw (20) << ite->second << setw (24) << ite->first << endl;
    }

    fin.close();
    fout.close();

    return 0;
}
开发者ID:Danielbook,项目名称:TNG033_-_Programmering_i_C-,代码行数:50,代码来源:uppgift1.cpp

示例2: main

int main(){
	int N;    
	in.open("input.txt"); out.open("output.txt");
	in >> N;
	
	int count = 0;
	for(int i=0;i<=30;i++){
		if(N&(1<<i))
			count++;
	}
		
	out<<count;
	return 0;
}
开发者ID:FreCap,项目名称:Algorithm-solutions,代码行数:14,代码来源:salti.cpp

示例3: main

int main (void)
{
	in.open("C-large-1.in");
	out.open("output.txt");

	int T;
	in >> T;

	printCase("hello world");

	in.close();
	out.close();
	return 0;
}
开发者ID:veezbo,项目名称:competitions,代码行数:14,代码来源:c.cpp

示例4: main

int main(int argc,char *argv[])
{
    string name,oname;
    int i;

    //char ts1[16] = "0.trace";
    //char ts2[12] = "0.symbol";
    //char ts3[10] = "1";


    if (argc != 4)
    {
        cout<<"Usage: trace2symbol inputfile outputfile $n\n"<<endl;
        return 0;
    }

    name.assign(argv[1]);
    //name.assign(ts1);
    oname.assign(argv[2]);
    //oname.assign(ts2);
    for (i=0; i<atoi(argv[3]); i++)
        //for (i=0;i<atoi(ts3);i++)
    {
        fin.open(name.c_str());

        if (fin.fail())
        {
            cout<<"Bad file name!\n"<<endl;
            return 0;
        }

        fout.open(oname.c_str());

        cout<<"Trace2Symbol(V1.0) "<<endl;

        cout << "Dealing with " << name << "...";

        work();

        fin.close();
        fout.close();
        fin.clear();
        fout.clear();

        cout << "Done." << endl;
        name=nextName(name);
        oname=nextName(oname);
    }
    return 0;
}
开发者ID:HDFGroup,项目名称:Replayer,代码行数:50,代码来源:trace2symbol.cpp

示例5: getData

string Hashr::getData(string files) {
	if (files != "") {
		dataReader.open(files, std::ios::binary | std::ios::in); //opens files as binary
		dataReader.seekg(0, std::ios::end); // moves curser to the end
		length = dataReader.tellg(); // gets position of the end
		dataReader.seekg(0, std::ios::beg); // moves cursor to beginning
		storage = new char[length]; // creates char array the length of the file
		dataReader.read((char*)storage, length);// stores the bits into storage
		dataReader.close(); //closes file
		std::string data(storage, length);
		return data;
	}
	return "";
}
开发者ID:jpc014,项目名称:Phile_Scanner,代码行数:14,代码来源:Hashr.cpp

示例6: promptUserForFile

//ask user to enter file name
string promptUserForFile(ifstream & infile, string prompt ){
    while(true){
        cout << prompt;
        string filename;
        getline(cin, filename);
        infile.open(filename.c_str());
        if(!infile.fail()) return filename;
        infile.clear();
        cout<<"UNABLE TO OPEN FILE! Try again."<<endl;
        if(prompt == ""){
            prompt = "Input filename: ";
        }
    }
}
开发者ID:shpp-mbondarenko,项目名称:cs-b-assignment1,代码行数:15,代码来源:FleschKincaid.cpp

示例7: get_store_data

void get_store_data (ifstream& myfile, string name_array[], float sales_array[][5]) // void function that gets the store data from file
{
    myfile.open("infile.txt");
    string name;
    for (int i = 0; i < 7; i++)
    {
        myfile >> name_array[i];
        for (int x = 0; x < 5; x++)
        {
            myfile >> sales_array[i][x];
            
        }
    }
}
开发者ID:haroldlomo15,项目名称:Using-1D-and-2D-Array-to-read-and-compute-data,代码行数:14,代码来源:main.cpp

示例8: openReadableFile

ID3_Err dami::openReadableFile(String name, ifstream& file)
{
  if (file.is_open())
  {
    file.close();
  }
  file.open(name.c_str(), ios::in | ios::binary | NOCREATE);
  if (!file)
  {
    return ID3E_NoFile;
  }
    
  return ID3E_NoError;
}
开发者ID:dalinhuang,项目名称:play-server,代码行数:14,代码来源:utils.cpp

示例9: openFiles

void openFiles(ifstream &ifile_stream, ofstream &ofile_stream) {
	string ifname, ofname;
	cout << "Please enter the name of the input text file: ";
	getline(cin, ifname);
	if(ifname.find(".txt") == string::npos)
		ifname += ".txt";
	ifile_stream.open(ifname.c_str());
	
	cout << "Please enter the name of the output text file where you would like to store the results: ";
	getline(cin, ofname);
	if(ofname.find(".txt") == string::npos)
		ofname += ".txt";
	ofile_stream.open(ofname.c_str());
}
开发者ID:timolawl,项目名称:codeeval,代码行数:14,代码来源:FizzBuzz.cpp

示例10: main

int main(){
	int N;    
	in.open("input.txt"); out.open("output.txt");
	in >> N;

	for(int i=1;i<=N;i++){
		S[t++]=i;
		f(i, N-i);
		t--;
	}
		

	return 0;
}
开发者ID:FreCap,项目名称:Algorithm-solutions,代码行数:14,代码来源:borse.cpp

示例11: open_file

void open_file(ifstream& file, char newpatern[10])
{
    char filenamedb[] = {'.','\\','d','a','t','a','b','a','s','e','\\'};
    char postfix [] = {'.','t','x','t','\0'};
    char filename[26];
    for (int i = 0; i < 26;i++)
        if (i < 11)
            filename[i] = filenamedb[i];
        else if (i < 21)
            filename[i] = newpatern[i-11];
        else
            filename [i] = postfix[i-21];
    file.open(filename);
}
开发者ID:njittam,项目名称:JhSolver,代码行数:14,代码来源:main.cpp

示例12: main

int main()
{
    fin.open("fence.in");
    fout.open("fence.out");

    fin >> f;

    for (int i = 0; i < f; ++i) {
        int a, b; fin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    // count vertex
    
    for (int i = 1; i <= 500; ++i) {
        if (g[i].size() > 0) {
            // make sure from small to large
            sort(g[i].begin(), g[i].end());
            vertexCount++;
        }
    }

    // calculate start vertex
    
    int startVertex;

    for (int i = 1; i <= 500; ++i) {
        if (g[i].size() > 0) {
            startVertex = i;
            break;
        }
    }

    for (int i = 1; i <= 500; ++i) {
        if ((g[i].size() & 1) == 1) {
            startVertex = i;
            break;
        }
    }

    selectVertex(startVertex);

    for (int v : path) {
        fout << v << endl;
    }

    return 0;
}
开发者ID:SummerWish,项目名称:USACO-solutions,代码行数:49,代码来源:fence.cpp

示例13: main

int main(){

	string ifname,ofname,command;
	cout << "Enter name of input file: ";
	getline(cin, ifname);
	cout << "Enter name of output file: ";
	getline(cin, ofname);
	infile.open(ifname.c_str()); // open takes c string
	outfile.open(ofname.c_str());
	if (infile.is_open())
		process_commands();
	else 
		cerr << "Error while opening input file" << endl;
	return 0;
}
开发者ID:rgruener,项目名称:DSA1_ECE164,代码行数:15,代码来源:assgnment1.cpp

示例14: openInFile

/********************************
** Function: void openInFile(ifstream &fin, string str);
** Description: Open the file and check for errors
**  throw exception if file open fails
**
**
** Parameters: ifstream fin is the file handle
**  string str is the name of the file to open
**
** pre-conditions: fin has been declared, str is a valid file name
** post-conditions: file opened and checked for errors in opening
********************************/
void openInFile(ifstream &fin, char str[])
{
     // can't open empty names
     if (str[1] == '\0') throw (-1);

     // attempt to open file
     fin.open(str);
     if (fin.fail())
     {
          cout << "SOMETHING WENT TERRIBLY WRONG! FAILED TO OPEN INPUT FILE"
               << endl;
          throw(-1);
     }
     return;
}
开发者ID:huffakco,项目名称:CS325Group6Project2,代码行数:27,代码来源:generateTest.cpp

示例15: main

int main()
{
	in.open(FILE_INPUT);
	out.open(FILE_OUTPUT);
	
	if(!in || !out) return 1;
	
	int N, P;
	in>>N>>P;
	if(P == 1) P_1(N);
	else P_2(N);
	in.close();
	out.close();
	return 0;
}
开发者ID:simonepri,项目名称:competitive-programming,代码行数:15,代码来源:scuola.cpp


注:本文中的ifstream::open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。