Thread: help please!!!!!

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    4

    help please!!!!!

    i am new to c++ and this is my second program for class...keep getting the error, warning: cannot pass objects of non-POD type 'struct std::string' through '...'; call will abort at runtime. can someone help me out please, here is my code:

    Code:
    #include <stdio.h>
    #include <cstdlib>
    #include <iostream>
    
    using namespace std; 
    
    // Input first and last name, grade, ande print out their name and lettergrade
    int main(int argc , char *argv)
    
    {
    	string name, grade, A, B, C, D, F;
    	
    	cout << "Please insert your first and last name:\n";
    	cin >> name;	
    	cout << "Please insert your numeric grade:\n";
    	cin >> grade;
    	name = name;
    	grade = grade;
    	if ("90" <= grade &&
    		grade <="100") A;
    	if ("80" <= grade &&
    		grade <= "89") B;
    	if ("70" <= grade &&
    		grade <= "79") C;
    	if ("60" <= grade &&
    		grade <= "69") D;
    	if (grade <= "59") F;
    	
    	printf("Hello name\n", name);
    	printf("You Made grade\n", grade);
    }

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    70
    printf only accepts c-style string, that is const char * typed strings. std::string has a method, c_str that will provide a c-style version of the string.
    Code:
    printf("Hello name\n", name.c_str());

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    And what would '...' be?

    Don't mix C and C++ like that. Use cout instead of printf.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    4
    thanks for the help i fixed it

Popular pages Recent additions subscribe to a feed