1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

I have a c++ problem if someone can help.

Discussion in 'Entertainment and Technology' started by Chic30, Dec 6, 2013.

  1. Chic30

    Regular Member

    Joined:
    Sep 23, 2013
    Messages:
    47
    Likes Received:
    0
    Location:
    Huntsville
    Gender:
    Female
    Sexual Orientation:
    Lesbian
    Out Status:
    Not out at all
    Ok, this is in my computer programming class and I'm not really understanding much. My professor gave us a problem which is: What is the output of the following code fragment?

    string msg = "knowledge";
    cout << "This is" << endl << "a test of your" << msg << endl << "." << endl;

    What exactly does he mean and can you explain. He's not good at explaining he has a lisp and he talks way to fast. Please help :confused::tears: i'm desperate.
     
  2. Ridiculous

    Full Member

    Joined:
    Dec 8, 2010
    Messages:
    3,583
    Likes Received:
    1
    Location:
    New Zealand
    cout is the standard output stream - this is sending stuff to the screen to be displayed.
    When you see the << operator on a stream, it means that something is being sent to that stream.
    The << operator can be chained together if you are sending multiple things to the same stream. For example
    Code:
    cout << "a" << "b" << "c" << "d";
    will have the same effect as
    Code:
    cout << "abcd";
    Both will display as abcd on the screen.

    So you've got stuff being sent to the cout stream, which will be displayed on the screen.

    endl is the same as a new line character for output streams - it just makes it start displaying on a new line after that point. (It also does some other things but that isn't important for this situation.)

    Remember that msg is a variable, so it will output what is stored in that variable.
     
  3. Pret Allez

    Full Member

    Joined:
    Apr 19, 2012
    Messages:
    6,785
    Likes Received:
    67
    Location:
    Seattle, WA
    Gender:
    Female (trans*)
    Gender Pronoun:
    She
    Sexual Orientation:
    Bisexual
    Out Status:
    Some people
    I think the best way to learn is by doing. So do you have a compiler available to you? Try this (example for GCC):

    main.cpp
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(int argc, char** argv)
    {
      string msg = "knowledge";
      cout << "This is" << endl << "a test of your" << msg << endl << "." << endl;
    
      return 0;
    }
    
    Code:
    g++ main.cpp -o main
    
    And then run your program and see what the result is.
     
  4. toushirojaylee

    Full Member

    Joined:
    Sep 21, 2013
    Messages:
    747
    Likes Received:
    0
    cool!I'm new on programming!
     
  5. Chic30

    Regular Member

    Joined:
    Sep 23, 2013
    Messages:
    47
    Likes Received:
    0
    Location:
    Huntsville
    Gender:
    Female
    Sexual Orientation:
    Lesbian
    Out Status:
    Not out at all
    I did something wrong, a second ago it was working fine. This is what i'm getting

    1>LINK : fatal error LNK1561: entry point must be defined
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
     
  6. Pret Allez

    Full Member

    Joined:
    Apr 19, 2012
    Messages:
    6,785
    Likes Received:
    67
    Location:
    Seattle, WA
    Gender:
    Female (trans*)
    Gender Pronoun:
    She
    Sexual Orientation:
    Bisexual
    Out Status:
    Some people
    What compiler are you using? Is the Microsoft compiler on Visual Studio?

    You need a function called main. The linker doesn't understand where your program starts.
     
    #6 Pret Allez, Dec 6, 2013
    Last edited: Dec 6, 2013
  7. Chic30

    Regular Member

    Joined:
    Sep 23, 2013
    Messages:
    47
    Likes Received:
    0
    Location:
    Huntsville
    Gender:
    Female
    Sexual Orientation:
    Lesbian
    Out Status:
    Not out at all
    Yes visual studio, and I think main is there. The thing is my professor added a template for us to use and he put it in there already. For some reason it's acting really strange.
     
  8. Pret Allez

    Full Member

    Joined:
    Apr 19, 2012
    Messages:
    6,785
    Likes Received:
    67
    Location:
    Seattle, WA
    Gender:
    Female (trans*)
    Gender Pronoun:
    She
    Sexual Orientation:
    Bisexual
    Out Status:
    Some people
    In your project settings, is it a console application or a Win32 application? If it's a Win32 application, then your application needs to have WinMain() and be written differently. I think it's easier if you make it a console application and use main() instead. Sorry, I am not really familiar with Windows development tools.

    http://social.msdn.microsoft.com/Fo...-entry-point-must-be-defined?forum=vclanguage

    Note to moderators: no, I don't post on MSDN, so this isn't a violation of the Code of Conduct. Ask Owen. Ze would know how I feel about all things Microsoft.
     
    #8 Pret Allez, Dec 6, 2013
    Last edited: Dec 6, 2013
  9. Chic30

    Regular Member

    Joined:
    Sep 23, 2013
    Messages:
    47
    Likes Received:
    0
    Location:
    Huntsville
    Gender:
    Female
    Sexual Orientation:
    Lesbian
    Out Status:
    Not out at all
    It says Win32 under solution platforms.
     
  10. Pret Allez

    Full Member

    Joined:
    Apr 19, 2012
    Messages:
    6,785
    Likes Received:
    67
    Location:
    Seattle, WA
    Gender:
    Female (trans*)
    Gender Pronoun:
    She
    Sexual Orientation:
    Bisexual
    Out Status:
    Some people
    I believe you want it to be a Win32 Console Application.
     
  11. Chic30

    Regular Member

    Joined:
    Sep 23, 2013
    Messages:
    47
    Likes Received:
    0
    Location:
    Huntsville
    Gender:
    Female
    Sexual Orientation:
    Lesbian
    Out Status:
    Not out at all
    Thank you guys so much.