Cant use as function...?

This is a discussion on Cant use as function...? within the C++ Programming forums, part of the General Programming Boards category; Its the newest book ive found :P . And i cant get getline to work i type cin.getline(string) and getline( ...

  1. #46
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Its the newest book ive found :P .

    And i cant get getline to work

    i type cin.getline(string)
    and getline( cin, string)
    and it says no matching functions for call to some gibberish83424ujrfh candidates are more giberish getline std giberuish

    Code:
    #include <iostream>
    #include <string>
    #include <windows.h>
    using namespace std;
    
    int main()
    {
      string theWord = ""; // do not need an array at all
    
      cout << "Enter a word to print 1 character at a time: ";
      cin.getline (theWord);
    
    
    for ( int i = 0; i < theWord.size(); i++ ) {
            cout << theWord[ i ] << "";
            Sleep(40);
        }
    return 0;
    }
    Nvm looked it up and copy pasted code and it worked but my code looked the same dont no why it didnt work :P
    Last edited by Nathan the noob; 02-17-2009 at 06:41 PM.

  2. #47
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    Quote Originally Posted by Nathan the noob View Post

    Wait!!! i found a bug with that formula...

    wats a way to get input were it doesnt skip blank spaces cause the program ends the for loop if theirs a blank space
    Try using std::getline() to read strings with spaces. cin >> has a draw back of stopping reading input then a space is reached.

    EDIT:

    And its

    Code:
    std::getline( std::cin, whateverthewordis );
    I'm just trying to be a better person - My Name Is Earl

  3. #48
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    I cant seem to figure out how to get my string to convert to upper case

  4. #49
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    toupper() and islower()
    I'm just trying to be a better person - My Name Is Earl

  5. #50
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    using islower() i get a error
    Code:
    #include <iostream>
    #include <string>
    #include <windows.h>
    using namespace std;
    
    int main()
    {
      string theWord = ""; // do not need an array at all
    
      cout << "Hello their input some words: ";
      getline (cin,theWord=islower());
      
    for ( int i = 0; i < theWord.size(); i++ ) {
            cout << theWord[ i ] << "";
            Sleep(100);
        }
    return 0;
    }
    to few arguments to function


    edit: Same with upper same error
    Last edited by Nathan the noob; 02-18-2009 at 10:03 AM.

  6. #51
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Whatever do you think that will do, or will work?
    Explain it to us, in words, on how you expect it to work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #52
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    The program or the islower() i expect islower() or toupper() to convert the string to either all lowercase or uppercase

  8. #53
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Indeed? And how would that work with this syntax?
    This is not even valid C++ syntax, so I fail to see how you can expect it to do such a thing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #54
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Nathan the noob View Post
    The program or the islower() i expect islower() or toupper() to convert the string to either all lowercase or uppercase
    Did you look up islower? or toupper? Specifically, did you look at what input is expected for the function and what output you get?

    And why do you think theWord=islower() makes any sense at all inside of a getline statement?

  10. #55
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Well i tried other ways to get it to work and it doesnt work with a string... is thier a different command or is their a way to convert string to char then char to string?
    Yes i did look it up

  11. #56
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Code:
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <cctype>
    
    int main()
    {
    	std::string s;
    	std::cout << "Hello there! Input some words: ";
    	std::getline(std::cin, s);
    	std::transform(s.begin(), s.end(), s.begin(), &std::tolower);
    	std::cout << "You entered: " << s << std::endl;
    }
    Hello there! Input some words: Hello There World!
    You entered: hello there world!

    Code:
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <cctype>
    
    int main()
    {
    	std::string s;
    	std::cout << "Hello there! Input some words: ";
    	std::getline(std::cin, s);
    	std::transform(s.begin(), s.end(), s.begin(), &std::toupper);
    	std::cout << "You entered: " << s << std::endl;
    }
    Hello there! Input some words: Hello There World!
    You entered: HELLO THERE WORLD!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #57
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    I just looked up begin and end im wondering the purpose of adding a second begin?
    Last edited by Nathan the noob; 02-18-2009 at 03:55 PM.

  13. #58
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Nathan the noob View Post
    I just looked up begin and end im wondering the purpose of adding a second begin?
    Did you look up transform?

  14. #59
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    I did yes but havent found what it does to add them..
    btw the code u wrote doesnt work it produced a error for me

    no matching function call to 'transform( gnu....)

  15. #60
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,409
    Elysia uses MSVC which, for whatever reason, doesn't "see" the possible ambiguity of the expression.

    Why don't you go and study a book or some tutorials? You have such a fundamental misunderstanding of C++ you'll never manage anything without asking for help on every single line. Asking for help is fine, but you are the limit. You will never accomplish anything asking for help with every breath.

    Punching the relevant error or the functions involved into Google will absolutely give you an answer, but you don't even bother doing that for yourself do you?

    Soma

Page 4 of 6 FirstFirst 123456 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  4. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 07:44 PM

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