| | |
Question about extra whitespace
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 15
Reputation:
Solved Threads: 0
I was given some code by my Professor and I had to debug it. I finally found the problem, but I have no idea why it is a problem. Could someone please enlighten me.
Here is the piece of the code that has been corrected:
Here is the original code piece with the error:
Why does it display what it does, instead of just add two spaces between each number?
Here is the piece of the code that has been corrected:
C++ Syntax (Toggle Plain Text)
. . . //Using negative subscripts cout<<"\nUsing negative subscripts"<<endl; p = a + n-1; for (size_t i =0; i < n ; ++i) cout << p[-i] << ' '; cout<< endl;
Here is the original code piece with the error:
C++ Syntax (Toggle Plain Text)
. . . //Using negative subscripts cout<<"\nUsing negative subscripts"<<endl; p = a + n-1; for (size_t i =0; i < n ; ++i) cout << p[-i] << ' '; // <------ There is an extra space. cout<< endl;
Why does it display what it does, instead of just add two spaces between each number?
that is the problem
c++ Syntax (Toggle Plain Text)
cout << 'a'; // good cout << ' '; // good cout << 'ab'; // bad cout << ' '; // bad
Last edited by NathanOliver; Sep 20th, 2009 at 9:56 pm.
if you write
If your thread is solved please mark it as solved
using namespace std; you do not need to write std::something in your program.If your thread is solved please mark it as solved
OK, you found the compile time error.
Now, there's still a potentially fatal logical error to be corrected.
Now, there's still a potentially fatal logical error to be corrected.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- Maxtor ext. hard-drive flashing lights. (Storage)
- Question about Program for Slope of a Line using a Class and Object (C++)
- Remove extra whitespace (C++)
- extracting an arbitrary number of numbers from a string (C)
- unable to connect (VB.NET)
- Preformatting (Java)
- A little help can go a long way (Motherboards, CPUs and RAM)
- I need help with my website. Using Dreamweaver. (JavaScript / DHTML / AJAX)
- Apple Mac mini (Apple Hardware)
Other Threads in the C++ Forum
- Previous Thread: Input a number and store it in an array
- Next Thread: is it a template related errors?
Views: 256 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






