| | |
why can't i convert please help
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 246
Reputation:
Solved Threads: 0
its in the num=="-".
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> using namespace std; int main() { cout <<"enter the problemset and number""\n"; //problems represents name and numbers string problems; char quote; char num; string number; //gather name if(cin.peek()=='"' || cin.peek() == '\'') { cin >>quote; getline(cin,problems,quote); } else { while (!isdigit(cin.peek()) && !isspace(cin.peek())) { (char)cin.peek(); problems += cin.get(); } } //gather problem numbers //cin >> num; int lastdigit=0; while(num != '\n'){ cin.get(num); // can't use cin >> ws since it would eat the newline /* while (cin.peek() != '\n' && isspace(cin.peek())) { cin.ignore(); }*/ if(num==',') { if(isdigit(cin.peek())) { cin.get(num); cout<<"from comma"<<number<<"\n"; } } else if (num=='-') { if(isdigit(cin.peek())) { // remember num int b=atoi(cin.get(num)); for(int a=lastdigit+1; a<=b; a++) { num++; } } else if(cin.peek()=='\n')// must be a newline! { // break; } else if(isdigit(cin.peek())) { } if(isdigit(num)) { lastdigit=num; } number=number+num; } cout<<"the final number is"<<number<<"\n"; // print them all out return 0; }
Hmmm.. don't know where to start from. First things first, 'num' is of type 'char', do you have a class 'char' which has a fn c_str defined? No. Its a fn of the 'string' class. Then you didn't even read my earlier post properly.
I guess you need to read up the chapters on the 'data types' a couple of times over. Read about int,char,double etc. Then read about arrays, chars and pointers. And then about the 'string' class. And then come back to this problem again.
I guess you need to read up the chapters on the 'data types' a couple of times over. Read about int,char,double etc. Then read about arrays, chars and pointers. And then about the 'string' class. And then come back to this problem again.
Last edited by Agni; Jun 29th, 2009 at 1:48 am.
thanks
-chandra
-chandra
Why don't you post the problem statement first. Then explain how you are trying to achieve it in your code. Then as I said, read about data-types. how did you find out about c_str fn? And I posted the correct function signature for atoi in my post above, does it have 2 parameters? Did you even read that?
thanks
-chandra
-chandra
![]() |
Similar Threads
- download pdf file, convert to html, in PHP since working in Linux (PHP)
- convert int to string (C)
- How to convert wav to mp3 using VB? (Visual Basic 4 / 5 / 6)
- cannot convert from 'double' to 'float [6][3]' (C)
- problem with convert jumbled text file to unjumbled text file (C)
- Need help to convert Int64 to Base36 ? (PHP)
- VC++:convert File IStream to hex and store...? (C++)
Other Threads in the C++ Forum
- Previous Thread: Fast copy operation
- Next Thread: Array Minimum and Maximum
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





