C + + Implementation TXT file read to another TXT file and replace it with a specific character of dictation

Source: Internet
Author: User

issue: a fopen error occurred: adding "_crt_secre_no_warnings" to the preprocessor

Reference: http://jingyan.baidu.com/article/ce436649fd61543773afd32e.html

Problem: A file read and write was done one afternoon and finally solved: code as follows:

Ifstream myfile ("F:\\1.txt");

Ofstream outfile ("F:\\pdataout.txt", Ofstream::app);

string temp;

if (!myfile.is_open ()) {cout << "file not successfully opened" << Endl; }

while (Getline (myfile, temp, ' \ n ')) {outfile << temp <<endl;  } myfile.close (); return 0;

problem: Originally read into a file can not achieve line, think a lot of methods can not achieve, quiet heart to: found with the problem in getline (myfile, temp,' \ n ')) ' \ n ' to achieve the end of the line.

problem : C + + code reads the entire contents of a text file to a string object at one time

Ifstream in ("Readme.txt", ios::in);  Istreambuf_iterator<char> Beg (in), end;  String Strdata (Beg, end); In.close ();

The entire contents of the Readme.txt can be read into the string object strdata.

problem : Replace all string characters

String::size_type pos = 0;
String s2 = "|";
string s3 = "";
String::size_type a = S2.size ();
String::size_type B = s3.size ();
while (pos = line.find (s2, pos))! = String::npos)
{
Line.replace (POS, 1, S3);
pos + = b;
}

problem: reading a string into the TXT file

outfile << line << Endl;

problem : A problem with the screen flash back

Add # include <stdlib.h> and System ("pause");

problem:C + + cannot find and open PDB files

Tools, Options, general (open source server), open symbol Miscrosoft source server;

If not, add GetChar () or system "pause"

C + + Implementation TXT file read to another TXT file and replace it with a specific character of dictation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.