• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:56
CET 14:56
KST 22:56
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Winners10Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1426 users

The Big Programming Thread - Page 38

Forum Index > General Forum
Post a Reply
Prev 1 36 37 38 39 40 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
jaydubz
Profile Joined February 2011
21 Posts
February 16 2011 17:42 GMT
#741
The problem is definitely making sense. I'm going to try to make some tweaks later tonight and see if I can get it to compile. Thanks for the help and suggestions so far!
Pigsquirrel
Profile Joined August 2009
United States615 Posts
Last Edited: 2011-02-17 16:54:43
February 17 2011 16:21 GMT
#742
I have a C++ question. How would I go about doing something like this:

#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;

int main () {
string fileName = "example.txt"
ofstream myfile;
myfile.open (fileName);
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}


It appears the string is the wrong variable type. What type should I use and is it possible anyway?

EDIT Google Came Through:


#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;

int main () {
string l="example.txt";
const char *p;
p=l.c_str();
ofstream myfile;
myfile.open (p);
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
February 17 2011 16:34 GMT
#743
If you read the documentation for ofstream::open you will find that the parameter must be a char*, however you are passing a object string.

To make it work, use filename.c_str(), since it returns a char* from your object string.
"When the geyser died, a probe came out" - SirJolt
Frigo
Profile Joined August 2009
Hungary1023 Posts
February 17 2011 16:34 GMT
#744
fileName.c_str() instead of fileName, this is a small design error of C++
http://www.fimfiction.net/user/Treasure_Chest
tofucake
Profile Blog Joined October 2009
Hyrule19151 Posts
February 17 2011 16:41 GMT
#745
It's not a design error.

Also, you need a semicolon.
Liquipediaasante sana squash banana
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
February 18 2011 00:51 GMT
#746
On February 18 2011 01:41 tofucake wrote:
It's not a design error.


It's just a pain in the ass and you'll run into the problem a lot. Thank god for the c_str() function! I started off programming in Java, so the whole C-style strings vs Strings thing still is weird to me.

I'm about to begin my first co-op (basically paid internship). I'm seeking one within software development or system administration (my two concentrations within IT). I have a moderate amount of experience with both Java and C++ (just started learning C++ this quarter but it has been easy to pickup), and very minimal with SQL (mySql only), CSS, and HTML. For those who have done internships, could you go into some detail with some of the work you ended up doing? I'm curious the types of things I should be practicing more on before I'm out programming for a company.

Undefeated TL Tecmo Super Bowl League Champion
heishe
Profile Blog Joined June 2009
Germany2284 Posts
February 18 2011 01:17 GMT
#747
On February 18 2011 01:21 Pigsquirrel wrote:
I have a C++ question. How would I go about doing something like this:

#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;

int main () {
string fileName = "example.txt"
ofstream myfile;
myfile.open (fileName);
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}


It appears the string is the wrong variable type. What type should I use and is it possible anyway?

EDIT Google Came Through:


#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;

int main () {
string l="example.txt";
const char *p;
p=l.c_str();
ofstream myfile;
myfile.open (p);
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}


Why do you use <iostream> <fstream> and then <string.h> instead of <string> ?
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
February 19 2011 06:24 GMT
#748
I notice a lot of job descriptions ask for a broad range of skills. I'm only good with Java and C++ and know the basics of MySQL, CSS, and HTML. Any suggestions for languages I should learn next? I'm a quick learner especially now that I have a decent "programming mindset" for these things.
Undefeated TL Tecmo Super Bowl League Champion
IKenshinI
Profile Joined April 2010
United States132 Posts
February 19 2011 06:39 GMT
#749
On February 19 2011 15:24 EscPlan9 wrote:
I notice a lot of job descriptions ask for a broad range of skills. I'm only good with Java and C++ and know the basics of MySQL, CSS, and HTML. Any suggestions for languages I should learn next? I'm a quick learner especially now that I have a decent "programming mindset" for these things.


Learn C
A cat is fine too
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
Last Edited: 2011-02-19 06:46:05
February 19 2011 06:45 GMT
#750
I was thinking about C# as one of the next ones I pick up. I read it's sort of like a mix between Java and C++, so should be quick to pickup. Is there a reason I would want to learn C? Does it do something better? It was my understanding that pretty much no company uses C. Rather they want people who know C# and C++ (along with other languages).
Undefeated TL Tecmo Super Bowl League Champion
Cloud
Profile Blog Joined November 2004
Sexico5880 Posts
Last Edited: 2011-02-19 06:49:46
February 19 2011 06:45 GMT
#751
On February 19 2011 15:24 EscPlan9 wrote:
I notice a lot of job descriptions ask for a broad range of skills. I'm only good with Java and C++ and know the basics of MySQL, CSS, and HTML. Any suggestions for languages I should learn next? I'm a quick learner especially now that I have a decent "programming mindset" for these things.


Maybe you want to shift your learning toward a different direction? Try learning Unix, always a good thing to have in your resume:
http://www.catb.org/~esr/faqs/loginataka.html

I think Oracle is a bigger standard than MySQL:
http://philip.greenspun.com/sql/

I can quote Peter Norvig on "teaching yourself programming in 10 years"
Learn at least a half dozen programming languages. Include one language that supports class abstractions (like Java or C++), one that supports functional abstraction (like Lisp or ML), one that supports syntactic abstraction (like Lisp), one that supports declarative specifications (like Prolog or C++ templates), one that supports coroutines (like Icon or Scheme), and one that supports parallelism (like Sisal).


Or an interesting blog post by a rather unknown person http://axisofeval.blogspot.com/2011/01/curing-pl-anxiety.html

And as ESR says, you're only good when you're recognized as good by other good programmers, and the best way to do that is to work on open source projects. Also possibly the very best thing to have in your resume (awesome if your interviewers can google you!)
http://freshmeat.net/
BlueLaguna on West, msg for game.
destian
Profile Joined August 2010
141 Posts
February 19 2011 06:46 GMT
#752
I have a question for anyone who's programming in the MVVM pattern. I'm working on a project that is showing ~30 text fields on a view. I can't help but think there has to be a better way than data binding 30+ properties. This seems wasteful. Any ideas?
Cloud
Profile Blog Joined November 2004
Sexico5880 Posts
February 19 2011 06:48 GMT
#753
On February 19 2011 15:45 EscPlan9 wrote:
I was thinking about C# as one of the next ones I pick up. I read it's sort of like a mix between Java and C++, so should be quick to pickup. Is there a reason I would want to learn C? Does it do something better? It was my understanding that pretty much no company uses C. Rather they want people who know C# and C++ (along with other languages).


There is one reason to learn C, and it's more than enough: Unix. Now C is not Unix so you actually have to learn Unix and not only C.
BlueLaguna on West, msg for game.
destian
Profile Joined August 2010
141 Posts
February 19 2011 06:49 GMT
#754
On February 19 2011 15:24 EscPlan9 wrote:
I notice a lot of job descriptions ask for a broad range of skills. I'm only good with Java and C++ and know the basics of MySQL, CSS, and HTML. Any suggestions for languages I should learn next? I'm a quick learner especially now that I have a decent "programming mindset" for these things.


If you have good experience with those two languages, it really is trivial to learn similar OOP languages. I'd suggest becoming more fluent in SQL. If you're leaning towards a company IT job, learning pivots in SQL will be invaluable.
haduken
Profile Blog Joined April 2003
Australia8267 Posts
February 19 2011 12:27 GMT
#755
On February 19 2011 15:46 destian wrote:
I have a question for anyone who's programming in the MVVM pattern. I'm working on a project that is showing ~30 text fields on a view. I can't help but think there has to be a better way than data binding 30+ properties. This seems wasteful. Any ideas?


30 text fields? Why not just show a grid?
Rillanon.au
haduken
Profile Blog Joined April 2003
Australia8267 Posts
February 19 2011 12:28 GMT
#756
Does anyone here use DevExpress winform? Why the hell does it crashes VS designer all the time...
Rillanon.au
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
February 19 2011 17:49 GMT
#757
Just curious, what is there to learn in C when you know a moderate amount of C++?

I can understand there might be different design issues, for example using structs instead of classes. But anything else? Learning unix libraries? :S


Also--- would it be wise to use the string class in c++, and then to go through the string use a string iterator? Instead of the traditional way with C strings, I'm wondering which one is the standard in industry: C++ strings or C strings, for C++ programming.
For example I can guess c++ string operations will be slower than on C-type strings, but it risk give you buffer overflows or alike.
England will fight to the last American
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2011-02-19 18:53:53
February 19 2011 18:01 GMT
#758
When you learn C (as someone who already knows C++), you don't actually learn a new language, you learn how to use a new programming paradigm (strictly structured instead of object oriented programming).

C as a language is syntactically identical to C++. C's grammar (the grammar of its formal language) and it's standard library of course have a lot of stuff missing that C++ has (classes etc., all of the stuff that comes with the STL, also C has no bool ), but other than that they're completely similar.


On February 20 2011 02:49 KaiserJohan wrote:

For example I can guess c++ string operations will be slower than on C-type strings, but it risk give you buffer overflows or alike.


The c++ string class can be accessed like a c-type string without any performance disadvantages:


#include <string>
#include <iostream>

void foo()
{

std::string my_string = "abcd"; //my_string("abcd") works too.

std::cout<<my_string[2]<<std::endl; //prints "c" followed by a new line
}



There should be no performance disadvantages using the [] operator as opposed to using iterators.

I'm not entirely sure, since I don't know the implementation of std::string, but the [] operator probably even is faster than iterating through the single chars manually.

Why do I think so? Well, internally std::string probably just manages a standard c-type array, which would make it's [] operator implementation as simple as this:


char operator[] (int i)
{
return m_ctype_char_array[i];
}


If you'd use iterators, you'd have to iterate through every char manually, which of course would be much much slower.

Note that your program will cause undefined behaviour if you try to access something outside the strings range, too, since std::string provides no protection from reading out of range stuff manually. When you iterate through the string using std::string::iterator or const_iterator manually, you can also acces stuff that is out of range by iterating "too far". Nothing saves you from that, as far as I'm aware.

As for your question:

On February 20 2011 02:49 KaiserJohan wrote:
Also--- would it be wise to use the string class in c++, and then to go through the string use a string iterator? Instead of the traditional way with C strings, I'm wondering which one is the standard in industry: C++ strings or C strings, for C++ programming.



In your usual application, of course using std::string is standard. It's just much more comfortable to use and provides a lot of functionality that an ordinary c-type char array doesn't have ( string a += "attachment"; for example )

But if you develop something in C++ where performance is really important (especially if you're trying to keep memory usage down) or where you don't need the extra std::string functionality, you might want to consider using standard c-type strings.

For example, if you just need the location of a file in a given method, you should consider using


void foo(const char *filename)
{
std::ofstream off(filename);
//do something with the file
o.close();
}


instead of using


void foo(std::string filename)
{
std::ofstream off(filename.c_str());
//do something with the file
o.close();
}


since std::string carries a very small (bet still existing) overhead compared to c-style strings in terms of memory usage.

filename.c_str() shouldn't be slower than directly handing over a const char *filename, since filename.c_str() should be inlined by your compiler, however, copying a string "into the method" when calling it might actually be slower than copying the pointer to a c-type char array, however I'm not sure about that.
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
February 20 2011 12:29 GMT
#759
I see, thanks for the clarification!
England will fight to the last American
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
February 21 2011 07:04 GMT
#760
I struggle a lot with fully grasping double linked lists using nodes in C++. I end up trying to draw everything out, a lot of scribbles, taking dozens of minutes designing out how I should be implementing it, and then still struggling when my design doesn't pan out. Any advice for how to get a better grasp on using double linked lists?

I'll be seeing my professor again tomorrow to help me better understand this. Just curious what any of you would recommend for getting better at it.
Undefeated TL Tecmo Super Bowl League Champion
Prev 1 36 37 38 39 40 1032 Next
Please log in or register to reply.
Live Events Refresh
CranKy Ducklings
10:00
Sea Duckling Open #140
CranKy Ducklings84
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 198
Railgan 42
Creator 14
StarCraft: Brood War
Sea 6776
Horang2 4135
GuemChi 1585
Jaedong 890
actioN 290
Mini 250
BeSt 249
Soma 228
Killer 218
EffOrt 205
[ Show more ]
Rush 172
Mind 105
Hyun 95
Bonyth 72
ToSsGirL 67
Backho 60
PianO 34
JYJ32
sas.Sziky 32
Aegong 28
zelot 23
Terrorterran 14
soO 11
sorry 10
HiyA 7
Sacsri 7
Dota 2
Gorgc5272
singsing2292
qojqva1976
Dendi596
XcaliburYe219
BananaSlamJamma107
Heroes of the Storm
Khaldor214
Other Games
B2W.Neo1235
Sick275
Lowko237
Fuzer 197
Hui .121
XaKoH 87
nookyyy 56
MindelVK20
Organizations
StarCraft 2
WardiTV622
Counter-Strike
PGL231
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 73
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2101
League of Legends
• Stunt689
• HappyZerGling108
Upcoming Events
IPSL
4h 5m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
4h 5m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
6h 5m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
9h 5m
Sparkling Tuna Cup
20h 5m
WardiTV Korean Royale
22h 5m
LAN Event
1d 1h
IPSL
1d 4h
JDConan vs WIZARD
WolFix vs Cross
BSL 21
1d 6h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
1d 19h
[ Show More ]
Wardi Open
1d 22h
WardiTV Korean Royale
2 days
Replay Cast
3 days
Kung Fu Cup
3 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
4 days
RSL Revival
4 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
4 days
WardiTV Korean Royale
4 days
RSL Revival
5 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
5 days
CranKy Ducklings
6 days
RSL Revival
6 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.