Thread: Help

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    1

    Angry Help

    Hi, Now I register.
    Thank 7stud!!
    I just try to write a program in C++. I knew it is very easy. but I can't not figure out whai's wrong?
    I want to read a very long string in a .txt file, and then split this string into many substrings (the length of each substring is 5).
    My code like this:

    #include <fstream>
    #include<string>
    #include<cctype>
    #include <iomanip>
    using namespace std;
    int main()
    {
    string text;
    string s[100000];
    int i,j,n,L,ll;
    L=5;

    const char* filename="aa.txt";
    ifstream inFile(filename);
    if (!inFile)
    {
    cout<<endl<<"Failed to open file"<<filename;
    return 1;
    }
    inFile>>text;
    ll=text.length();
    n=ll/L;
    i=0;
    while (i<n)
    {
    j=i*L;
    s[i]=text.substr(j,L);
    i++;
    }
    }

    The input file seq.txt, look like:
    1234111333344455565667777888888, so
    s[0]="12341"
    s[1]="11333"......

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    ll=text.size();

    Kuphryn

Popular pages Recent additions subscribe to a feed