Newbie having problem with strings

This is a discussion on Newbie having problem with strings within the C++ Programming forums, part of the General Programming Boards category; To All, I was trying to learn c++ using the tutorials posted on cprogramming.com when I encountered a problem. I ...

  1. #1
    sunzoner
    Guest

    Question Newbie having problem with strings

    To All,

    I was trying to learn c++ using the tutorials posted on cprogramming.com when I encountered a problem. I copied the codes directly from the website, but there is some errors. Can someone tell me what is the problem?
    There are more errors but I did not put them all in. What should I do?

    Thanks in advance.

    Errors:
    [warning] in function 'int main()':
    line 4: [warning] overflow in implicit constant conversion
    line 6: no matching function for call to '_io_stream_withassign::getline(char &, int, char)'

    code:
    #include <iostream.h>
    int main()
    {
    char string(256);
    cout<< "Please enter a long string";
    cin.getline(string, 256, '\n');
    cout<< "Your long string was: "<< endl<<string;
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Location
    Australia
    Posts
    212
    Use <iostream> not <iostream.h>

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Corrections in bold

    Code:
    #include <iostream.h> 
    int main() 
    { 
    char string[256]; 
    cout<< "Please enter a long string"; 
    cin.getline(string, 256, '\n'); 
    cout<< "Your long string was: "<< endl<<string; 
    return 0; 
    }
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Originally posted by kwigibo
    Use <iostream> not <iostream.h>
    yeah he should, but that's not what's causing him problems. It's not what's preventing the program from compiling.

    it's alright......just not really up to the "new standard" but compiles alright.......


    This is probably what kwigibo is refering to.

    Code:
    #include <iostream> 
    using std::cout;
    using std::cin;
    using std::endl;
    int main() 
    { 
    char string[256]; 
    cout<< "Please enter a long string"; 
    cin.getline(string, 256, '\n'); 
    cout<< "Your long string was: "<< endl<<string; 
    return 0; 
    }
    Last edited by incognito; 05-21-2002 at 09:39 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 11:47 PM
  2. Problem with comparing strings!
    By adrian2009 in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 10:44 PM
  3. Replies: 8
    Last Post: 07-18-2005, 06:53 AM
  4. Problem with reading strings
    By goron350 in forum C++ Programming
    Replies: 8
    Last Post: 06-05-2005, 01:05 AM
  5. Problem with strncat() function (newbie)
    By Kettch in forum C Programming
    Replies: 2
    Last Post: 12-08-2001, 02:54 AM

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