Thread: Searching through a string....

  1. #1
    neocryptica
    Guest

    Searching through a string....

    I am righting an app that uses a flat file (myVar.txt) to interface with an app I developed in Flash 5, and I'm having a bit of difficulty:

    I am setting the variables fine from both flash and C++, but I am
    trying to sort through an array that I populated as such;

    // Declare the storage array
    char cMyStream[50];

    // Assign the string conents of myVar.txt
    ifstream mystream("\myVar.txt");
    if(!mystream)
    {
    cout << "Cannot open file.\n";
    }

    // Assign the conent of mystream to cMyStream
    mystream >> cMyStream;
    My problem is this...
    the text file uses a variable format of &Var1=234&Var2...
    I want to sort through the variables to return the values of Var1 and Var2 to an array, but lack the knowledge to do so...
    Please help!!!

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    If the value for each variable always occurs after the = character, you could use this as the delimeter. Read the characters using getline(), and then read the value into you array of integers.

    mystream.getline(char_buff,sizeof(char_buff),'=');
    mystream >> int_array[i++];

    Put this code in a loop that reads until the end of the file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  2. Need help on String Searching.
    By RP319 in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2005, 10:33 PM
  3. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM