![]() |
| | #1 |
| Registered User Join Date: Jul 2008
Posts: 44
| I'm getting a warning when I try to do the (char *) cast on &buf, What is the correct cast for this? The warning I get is : use of old-style cast Thanks, Ed. Code: char buf[3][20];
inline void readInRow() {
currentData.clear();
mIn.read((char *) &buf, sizeof(buf));
for (int i=0; i < 3; ++i)
currentData.push_back(string(buf[i]));
printout(currentData);
cout << endl;
}
|
| afflictedd2 is offline | |
| | #2 |
| Registered User Join Date: Jun 2008 Location: RING 0
Posts: 468
| Why can't you just pass it buf? I also dont think you can cast an array to a pointer...but if you could i believe the syntax would be (char **) for 2-d arrays. |
| valaris is offline | |
| | #3 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| I think istream::read() expects a char *, but you probably don't want to use &buf, but rather buf. And since this is C++, you should use Code: mIn.read(reinterpret_cast<char *>(buf), sizeof(buf)); Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #4 |
| and the hat of sweating Join Date: Aug 2007 Location: Toronto, ON
Posts: 3,282
| Why not just pass buf[0] instead of forcing a 2D array to look like a 1D array? Then you shouldn't need any casts. |
| cpjust is offline | |
| | #5 | |
| Registered User Join Date: Jul 2008
Posts: 44
| Thanks matsp, that worked beautifully. Quote:
![]() Ed. | |
| afflictedd2 is offline | |
| | #6 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,836
| You got it right here: Code: currentData.push_back(string(buf[i])); |
| tabstop is online now | |
| | #7 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
-- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
| matsp is offline | |
| | #8 | |
| and the hat of sweating Join Date: Aug 2007 Location: Toronto, ON
Posts: 3,282
| Quote:
Code: for ( int x = 0; x < 3; ++x )
mIn.read( buf[x], sizeof(buf[x]) );
| |
| cpjust is offline | |
| | #9 |
| Registered User Join Date: Jul 2008
Posts: 44
| |
| afflictedd2 is offline | |
| | #10 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| That's fine then - it's just that I've seen quite a few posts where someone is trying to read a text-file using read (or write it using write) and then complaining that the code doesn't work right - usually pointing at some completely different portion of code [such as the output or calculations]. I was just making sure that you are doing things the way they are meant to be done. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Including The Right DLLs | bumfluff | Game Programming | 8 | 12-28-2006 03:32 AM |
| How to fix misaligned assignment statements in the source code? | biggyK | C++ Programming | 28 | 07-16-2006 11:35 PM |
| Converting Double to Float | thetinman | C++ Programming | 7 | 06-17-2006 02:46 PM |
| errors in class(urgent ) | ayesha | C++ Programming | 1 | 11-10-2001 10:14 PM |
| errors in class(urgent) | ayesha | C++ Programming | 2 | 11-10-2001 06:51 PM |