Super newbie questions

This is a discussion on Super newbie questions within the C++ Programming forums, part of the General Programming Boards category; Have a look Mats: Code: #include <iostream> #include <string> #include <sstream> using namespace std; int main() { sringstream sinout; sinout ...

  1. #16
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Have a look Mats:

    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std;
    
    int main()
    {
    	sringstream sinout;
    	sinout << "number: " << 13 << "is un-unlucky!";
    	string s;
    	sinout >> s;
    	cout << s << endl;
    	return 0;
    }
    error C2065: 'sringstream' : undeclared identifier
    c:\my\src\cpp\test-bed\test-bed.cpp(94) : error C2146: syntax error : missing ';' before identifier 'sinout'

  2. #17
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,658
    Argh, come on people. Effort! manav, just read the error: what is the typo supposed to be written as? You can do it.

  3. #18
    Banned
    Join Date
    Nov 2007
    Posts
    678
    i can't! sorry!! what's the typo?

    EDIT: damn! so sorry citizen! so sorry Mats!
    Last edited by manav; 04-16-2008 at 07:12 AM.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by manav View Post
    i can't! sorry!! what's the typo?
    sringstream should be stringstream.

    Because it's such a long (and single case) name, it's hard to spot the missing t.

    --
    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.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Because it's such a long (and single case) name, it's hard to spot the missing t.
    Slightly off topic:
    I have been known to #include <iosteam>
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std;
    
    int main()
    {
    	stringstream sinout;
    	sinout << "number: " << 13 << "is un-unlucky!";
    	string s;
    	sinout >> s;
    	cout << s << endl;
    	return 0;
    }
    compiles fine!
    runs strange!!

    output>>
    number:

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, stringstream, like iostreams, stops reading strings on encountering a space - use getline if you want to avoid that. Which is one reason my example didn't include any text [the other reason is that I'm too lazy].

    --
    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.

  8. #23
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    That output is expected, since "number:" is the first substring in the stream before the first whitespace character.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #24
    Banned
    Join Date
    Nov 2007
    Posts
    678
    yeah . . .
    i again wish that this was possible:
    Code:
    string s;
    s << "number:" << 13 << " is un-unlucky!";

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by manav View Post
    yeah . . .
    i again wish that this was possible:
    Code:
    string s;
    s << "number:" << 13 << " is un-unlucky!";
    This will do what you want (I'm 99% sure)
    Code:
    stringstream ss;
    ss << "number:" << 13 << " is un-unlucky!";
    string s = ss.str();
    --
    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.

  11. #26
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    We could modify your example to work as you apparently want it to work:
    Code:
    stringstream sinout;
    sinout << "number: " << 13 << "is un-unlucky!";
    string s(sinout.str());
    cout << s << endl;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #27
    Banned
    Join Date
    Nov 2007
    Posts
    678
    thanks Mats!
    it fails laserlight! just the same as i posted!

  13. #28
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    it fails laserlight! just the same as i posted!
    I think you looked at my accidental posting... I hit the "post quick reply" button while trying to edit your example.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #29
    Banned
    Join Date
    Nov 2007
    Posts
    678
    wow! the speedy helpers! but very nice! all of you! thanks!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory handling functions (newbie questions)
    By PaulBlay in forum C Programming
    Replies: 6
    Last Post: 03-10-2009, 06:37 AM
  2. newbie questions
    By raptorx in forum C Programming
    Replies: 2
    Last Post: 10-10-2007, 09:30 PM
  3. Newbie Questions
    By snoopy1 in forum C++ Programming
    Replies: 3
    Last Post: 11-19-2006, 01:00 PM
  4. Real newbie with VC6 questions
    By MagiZedd in forum Windows Programming
    Replies: 8
    Last Post: 10-15-2001, 08:27 PM
  5. newbie questions again
    By dune911 in forum C++ Programming
    Replies: 2
    Last Post: 09-14-2001, 02:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21