Rows and colums

This is a discussion on Rows and colums within the C++ Programming forums, part of the General Programming Boards category; If you are reading a .dat file or a .txt file and you have text in it like: Look at ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Rows and colums

    If you are reading a .dat file or a .txt file and you have text in it like:

    Look at the cat
    and look at the [dog]
    the [sky] is blue

    Is there a way to identify the location of a character? For instance the d in dog would be LINE 2, ROW 18. Is there some function in C++ that can be used to do this with?
    Last edited by Aluvas; 11-14-2002 at 06:14 PM.

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Load all of the data into a vector of strings. Then, search through it.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    11

    or...

    I'm working on my program right now with strings. I tried to play with this command a little bit, but it might at least help you.

    If you read in each like as a string, you can use the "find()" function. It goes something like this:

    Code:
    ifstream in ("filename");
    string blah;
    
    while (!in.eof())
    {
       in >>blah;
       cout <<blah.find("d") <<endl;
    }
    I have to work on my own program, but that might be something to think about... instead of trying to populate an array with an entire paragraph or something. You can just search one word at a time. I'll leave it up to you to think of some creative way to get it to tell you what row its in. This function will only return the array position "d" is in each word. One drawback, if the letter "d" is not in the word, it returned a very large number. Oh yes, in order to use the variable type "string" and the "find()" function, you will have to include the string library which could be:

    Code:
    #include <cstring>
    #include <string>
    #include <string.h>
    I have to use "#include <string>"

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    7
    Thanks that simple enough.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Swapping rows in a 2D array
    By bassist11 in forum C Programming
    Replies: 5
    Last Post: 03-11-2010, 11:04 AM
  2. displaying with rows and colums
    By tio1225 in forum C++ Programming
    Replies: 1
    Last Post: 09-23-2005, 05:07 PM
  3. printing rows and columns
    By datainjector in forum C# Programming
    Replies: 1
    Last Post: 08-03-2003, 05:42 PM
  4. "subscript requires array or pointer type"?
    By Nutka in forum C Programming
    Replies: 12
    Last Post: 12-06-2002, 04:51 PM
  5. making an empty 2-D array
    By starX in forum C Programming
    Replies: 4
    Last Post: 02-08-2002, 12:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21